qt - Why does QComboBox ignore its fixed vertical size policy? -
i have widget 2 stacked layers. first looks this, fine:
the second looks this, wrong.
here complete code produces widget , prints size policies.
#include <qtwidgets> int main (int argc, char ** argv) { qapplication app (argc, argv); qwidget w; auto stack = new qstackedwidget (); qwidget * labelbox = new qwidget (); qwidget * combobox = new qcombobox (); qwidget * label = new qlabel ("label"); qwidget * button = new qpushbutton ("button"); qwidget * date = new qdatetimeedit (); auto gl = new qgridlayout (& w); auto hl = new qhboxlayout (labelbox); hl -> addwidget (label); hl -> addwidget (button); stack -> addwidget (labelbox); stack -> addwidget (combobox); stack -> setcurrentindex (1); // 0 layer, 1 bad gl -> addwidget (date); gl -> addwidget (stack, 0, 1); w .setminimumsize (300, 200); w .show (); (auto x : {(qwidget *) stack, labelbox, combobox, label, button, date}) { qwarning () << x -> metaobject () -> classname () << x -> sizepolicy (); } return app .exec (); }
the stdout follows:
qstackedwidget qsizepolicy(horizontalpolicy = 5, verticalpolicy = 5) qwidget qsizepolicy(horizontalpolicy = 5, verticalpolicy = 5) qcombobox qsizepolicy(horizontalpolicy = 5, verticalpolicy = 0) qlabel qsizepolicy(horizontalpolicy = 1, verticalpolicy = 5) qpushbutton qsizepolicy(horizontalpolicy = 1, verticalpolicy = 0) qdatetimeedit qsizepolicy(horizontalpolicy = 1, verticalpolicy = 0)
the documentation these values is:
qsizepolicy::fixed = 0 qwidget::sizehint() acceptable alternative, widget can never grow or shrink (e.g. vertical direction of push button). qsizepolicy::growflag = 1 widget can grow beyond size hint if necessary. qsizepolicy::expandflag = 2 widget should space possible. qsizepolicy::shrinkflag = 4 widget can shrink below size hint if necessary. qsizepolicy::ignoreflag = 8 widget's size hint ignored. widget space possible.
so looks vertical size policies fixed
except qstackedwidget
, qwidget
contains label , button, , qlabel
, have growflag|shrinkflag
.
why qcombobox
grow vertically, despite fixed
policy? why not happen qpushbutton
or qdatetimeedit
?
this happens qt 4.8 , qt 5.1 on ubuntu 15.04.
you assigning combo box directly qstackedwidget haven't added qlayout first. assign layout, add layout qwidget , add qwidget qstackedwidget.
example:
qwidget * combowidget = new qwidget (); qwidget * combobox = new qcombobox (); auto vl = new qvboxlayout (combowidget); vl->addwidget(combobox); stack->addwidget (combowidget);
Comments
Post a Comment