c++ - QSplitter - changing the size of QTabWidget -
i have qtabwidget , layout. want tabs of qtabwidget occupy width of qtabwidget have this. following method expands 2 tabs in qtabwidget same size qtabwidget
void contacts::adjusttabs( int pos, int index ) { std::string orig_sheet = ui.tabwidget->stylesheet().tostdstring(); qstring new_style = qstring("qtabbar::tab { width: %1px; } ").arg((ui.tabwidget->size().width() /ui.tabwidget->count())); std::string t = new_style.tostdstring(); orig_sheet = orig_sheet + t; ui.tabwidget->setstylesheet(orig_sheet.c_str()); }
the above method works fine. problem starts when qtabwidget set in qsplitter layout along other layout.at startup construction above method not seem work instance have this
someclass::someconstructor() { ui.setupui(this); ......... qobject::connect(ui.splitter,signal(splittermoved(int,int)),this,slot(adjusttabs(int,int))); adjusttabs(0,0); }
now when form appears horizontal size of tabs remain unchanged (they not expand - wrong). when move splitter tabs expand , fine. question how can make tabs expand during form load ? why arent expanding ?
i think trying explicitly adjust tabs' sizes whenever resize event occurs isn't best approach. if things set properly, appropriate size adjustments should naturally occur due default behavior of qsplitter , qtabwidget's internal layout managers. here simple example of mean; note there no code in program explicitly handle resizing of anything, , yet tabs resize correctly splitter moved and/or window resized:
#include <qapplication> #include <qmainwindow> #include <qpushbutton> #include <qsplitter> #include <qtabwidget> int main(int argc, char *argv[]) { qapplication a(argc, argv); qmainwindow mw; qsplitter * splitter = new qsplitter(&mw); qtabwidget * tab = new qtabwidget; tab->addtab(new qpushbutton("content of tab #1"), "tab #1"); tab->addtab(new qpushbutton("content of tab #2"), "tab #2"); tab->addtab(new qpushbutton("content of tab #3"), "tab #3"); splitter->addwidget(tab); splitter->addwidget(new qpushbutton("some other content")); mw.setcentralwidget(splitter); mw.show(); return a.exec(); }
so question becomes -- why aren't tabs resizing automatically? perhaps there have sizepolicy property set fixed, rather preferred or ignored?
Comments
Post a Comment