How to set the size percentage of a QWidget
-
-
for this we need the dimensions and dimensions vary thats why i want percntage of width if there is a way to directly setting the percntage of parent element
dimensions change so by your method get the deimensions and get the percentage and create a resize event but in percentage it can be direct and better -
I'm not sure that i understood correctly what you want, but i think you need the "stretch":http://qt-project.org/doc/qt-4.8/qsizepolicy.html#setVerticalStretch factor (see the horizontal too)
I'm not exactly sure how it works, but it looks it's something like: if we have 2 widgets: first with stretch factor 1 and second with 2 the second will have 2/3 from the parent and first 1/3 (but you can play with the values and see what's close to what you want)
-
hey "Zlatomir":https://qt-project.org/member/1233
you understand it correctly yes its m solution i have get my solution thanks man -
You play with values, i don't know exactly what those ints mean, anyway here is a little example:
@int main(int argc, char** argv)
{
QApplication a(argc, argv);QWidget parent(0); QLabel* w0 = new QLabel("red"); w0->setStyleSheet("QLabel { background-color : red; color : blue; }"); QSizePolicy policy0 = w0->sizePolicy(); policy0.setHorizontalStretch(2); w0->setSizePolicy(policy0); QLabel* w1 = new QLabel("green"); w1->setStyleSheet("QLabel { background-color : green; color : blue; }"); QSizePolicy policy1 = w1->sizePolicy(); policy1.setHorizontalStretch(1); w1->setSizePolicy(policy1); QHBoxLayout* layout = new QHBoxLayout(&parent); layout->addWidget(w0); layout->addWidget(w1); parent.show(); return a.exec();
}@