qt - QMdiArea: First tab works fine, second tab's content is way too small -
situation: central widget of application have qmdiarea in tabbed mode (wrapped in custom class inherited qmdiarea). when add first qmdisubwindow via addsubwindow()
still fine, meaning window , contents maximized take space of qmdiarea. however, add second sub window, following problem arises:
problem: content of second window not displayed, instead content first continues (despite fact second tab visually has focus), reduced in size. takes few pixels. if switch first sub window/tab (either clicking size-reduced widget automatically goes max size or selecting first tab header) , selecting 2nd again, fine = widget/editor of 2nd tab displayed , maximized.
but until close second tab, in case content first displayed (as expected), again in small size!
screenshot:
another related test case: 1st tab created , displayed full size expected. if resize overall qmainwindow, faint border appears around widget in tab. appears in mixed state between maximized , normal mode borders. create new leads?
screenshot:
i far not using explicitly defined layouts, given first tab works fine , after manual back-and-forth switching others well, assume should work without.
do need set explicit layout objects? why work first tab, not second?
some code base: logic executed in custom qmdiarea class takes care of adding new children:
// note: peditor inherits / qmdisubwindow if(!peditor->isinitialized()) { peditor->initialize(); peditor->setwidget(peditor->geteditorwidget()); peditor->setinitialized(true); } peditor->beforedisplay(); addsubwindow(peditor); peditor->showmaximized(); // hack start pexisting = subwindowlist().at(0); if(pexisting) setactivesubwindow(pexisting); // hack end
update: added hack proposed n1ghtlight. marked such in coding.
update 2: edited / correct problem description + new test-case screenshot.
after many hours of comparing example project n1ightlight own implementation, came across central differences. there in fact 2 issues @ play:
for reason had following line in creation of mdi sub windows, apparently screwed size handling. getting rid of line removed need proposed hack. combined layouting proposed n1ghtlight, size changes handled gracefully.
setwindowstate(qt::windowmaximized); // not use state!
the second part regarding tab closing (closing 1 tab did not bring next tab in expected manner , size), explained in qt documentation:
when create own subwindow, must set qt::wa_deleteonclose widget attribute if want window deleted when closed in mdi area. if not, window hidden , mdi area not activate next subwindow.
since creating own sub windows had set flag, never did because wanted prevent qt automatically deleting content widget well. solution set flag, whenever mdi child closed, remove link widget, qt cannot delete it.
void custommdiwindow::closeevent(qcloseevent* pevent) { setwidget(0); pevent->accept(); }
i mark own answer correct one, award bounty n1ightlight since support led me finding final solution.
Comments
Post a Comment