resize - Resizing a Qt window when a child element has been removed. -
i have qwidget window, contains qsplitter. have qstackedlayout (within qwidget container) on both left , right of splitter. main application resides in left region, can trigger qwebviews appear on right. when remove right qwebview, window attempts resize, stays @ width of qwebview. when try drag window, snaps position around left side of splitter.
i want window snap show left side of splitter on removing last widget right qstackedwidget. i've tried various incantations, don't know qt well, , attempting learn go.
the below code in java, using jambi wrappers. concepts should same in c++, , i'm able translate other language binding jambi if necessary.
i attempt set window minimum width on add , remove of widgets rightstackedlayout, breaks splitter handle in cases. consider hack workaround. if can point me in right direction of having changes right side of splitter update top level window, i'll grateful.
// main window class public window() { // #qwidget super(); this.setcontentsmargins(0, 0, 0, 0); qhboxlayout mainlayout = new qhboxlayout(this); mainlayout.setcontentsmargins(0, 0, 0, 0); splitter = new qsplitter(); qwidget leftcontainer = new qwidget(); qwidget rightcontainer = new qwidget(); leftlayout = new qstackedlayout(); rightlayout = new rightstackedlayout(); leftcontainer.setlayout(leftlayout); rightcontainer.setsizepolicy(new qsizepolicy(qsizepolicy.policy.expanding,qsizepolicy.policy.expanding)); rightcontainer.setlayout(rightlayout); splitter.addwidget(leftcontainer); splitter.addwidget(rightcontainer); splitter.setstretchfactor(0, 0); // not resize left splitter.setstretchfactor(1, 1); // resize right splitter.setwindowstate(windowstate.windowmaximized); mainlayout.addwidget(splitter); } public void denywidthchange() { // when right side closed, prevent user resizing horizontally this.setsizepolicy(new qsizepolicy(qsizepolicy.policy.fixed,qsizepolicy.policy.preferred)); this.splitter.setsizepolicy(new qsizepolicy(qsizepolicy.policy.fixed,qsizepolicy.policy.preferred)); this.splitter.updategeometry(); this.updategeometry(); } public void allowwidthchange() { // when right side open, allow user expand horizontally this.setsizepolicy(new qsizepolicy(qsizepolicy.policy.expanding,qsizepolicy.policy.expanding)); this.splitter.setsizepolicy(new qsizepolicy(qsizepolicy.policy.expanding,qsizepolicy.policy.expanding)); this.splitter.updategeometry(); this.updategeometry(); } public void adjustsizes(int w, int h) { this.resize(w, h); this.splitter.resize(w, h); } // rightstackedlayout public void add(qwidget widget) { application.window.allowwidthchange(); application.window.setminimumwidth(((webpane)widget).minwidth()+this.rememberwidth); // left side + right side qwidget current = this.currentwidget(); if (current != null) { this.rememberwidth = current.size().width(); // remember user resize preferences } int idx = this.indexof(widget); if (idx == -1) { widget.setminimumwidth(this.rememberwidth); this.addwidget(widget); } this.setcurrentwidget(widget); } public void remove(qwidget widget) { application.window.allowwidthchange(); this.removewidget(widget); this.update(); if (this.count() == 0) { log.debug("last rightwebpane closing: shrinking window"); this.rememberwidth = widget.size().width(); this.activate(); //((qwidget)this.parent()).resize(0, 0); application.window.setminimumwidth(((webpane)widget).minwidth()); application.window.adjustsizes(0,application.window.height()); application.window.denywidthchange(); } }
while still haven't got functional resizing policy happening, i'm of way , figured out problem having had not taking splitter.handlewidth() account when attempting calculate total width.
Comments
Post a Comment