i know how can create widget automatically fit space when edit height of qdialog contain widget.
in exemple bellow, qpushbutton fit width of qdialog not height. however, if create qtextedit instead of qpushbutton, qtextedit fit qdialog.
from pyside.qtgui import * class c (qdialog): def __init__(self): qdialog.__init__(self) self.setlayout(qvboxlayout()) self.layout().setspacing (0) self.layout().setcontentsmargins(0,0,0,0); btn = qpushbutton() self.layout().addwidget(btn) self.exec_() = c()
the c++ documentation of qboxlayout class states for
qboxlayout::addwidget(widget, stretch=0, alignment=0) if stretch factor 0 , nothing else in qboxlayout has stretch factor greater zero, space distributed according qwidget:sizepolicy() of each widget that's involved.
so having @ default policy of qpushbutton
>>> btn = qpushbutton() >>> btn.sizepolicy().horizontalpolicy() 1 >>> btn.sizepolicy().verticalpolicy() 0 we'll find, vertical policy fixed. adding button like
[...] btn = qpushbutton() policy = btn.sizepolicy().horizontalpolicy() btn.setsizepolicy(policy, policy) self.layout().addwidget(btn) [...] will automatically adjust button dialog.
Comments
Post a Comment