user interface - Qt- How to position UI elements like this? -
i creating ui in qt has qdockwidget containing qpushbutton , qlineedit. please refer attached mock-up. have created widget components , got them , running. not positioned way want them to. both elements should float left making space right stretch when window resized.
the code-
this->searchfield = new qlineedit; //"this" qdockwidget subclassed object searchfield->setfixedwidth(200); mainmenu = new menu(); qhboxlayout *layout= new qhboxlayout; qspaceritem *filler = new qspaceritem(1000, 10); layout->addwidget(mainmenu->getmenubar()); layout->addwidget(this->searchfield); layout->addspaceritem(filler);
any suggestion or awesome! time :)
http://qt-project.org/doc/qt-4.8/layout.html
http://qt-project.org/doc/qt-4.8/qboxlayout.html#addstretch
void qboxlayout::addstretch ( int stretch = 0 )
adds stretchable space (a qspaceritem) 0 minimum size , stretch factor stretch end of box layout.
so new code like:
this->searchfield = new qlineedit; searchfield->setfixedwidth(200); mainmenu = new menu(); qhboxlayout *layout= new qhboxlayout; layout->addwidget(mainmenu->getmenubar()); layout->addwidget(this->searchfield); layout->addstretch(); // added
hope helps.
Comments
Post a Comment