PDA

View Full Version : qlayout and setGeometry



mickey
1st April 2006, 23:09
Hi, I can't set dimension of vlay0 (or wid0) how my own; I'd like set its width such as the width of a checkBox; I tried every setGeometry but seems don't work. Why?


QGroupBox* box = new QGroupBox (myFrame);
box->setGeometry(5,5,myFrame->width()-10, myFrame->height()-10);
box->setTitle("title");
QWidget* wid = new QWidget(box);
QWidget* wid0 = new QWidget(wid);
wid->setGeometry(QRect (20,20,100,50));
wid->setBackgroundColor(QColor (10,100,50));

wid0->setGeometry(QRect (0,0,5,20));
QBoxLayout* hlay = new QHBoxLayout (wid);
QCheckBox* c0 = new QCheckBox(wid0);
c0->setBackgroundColor(QColor (10,100,50));
QVBoxLayout* vlay0 = new QVBoxLayout (wid0);
QLabel* l0 = new QLabel (wid0);
l0->setText("l0");
l0->setBackgroundColor(QColor (100,1,150));
vlay0->addWidget(c0);
vlay0->addWidget(l0);
hlay->addWidget(wid0);

wysota
2nd April 2006, 10:43
You can't use setGeometry() when using layouts -- it'll simply not work. If you want to manipulate sizes of laid out widgets, you have to use sizeHint, sizePolicies and minimumSize and maximumSize properties.

And remember to set a layout for that group box. It doesn't have one and maybe if you set it, all other widgets will stretch accordingly.

mickey
2nd April 2006, 11:40
ok for before. but for example: how I can set the square of check in the middle
of purple? Thaks; it seems not possible...


QWidget* wid = new QWidget(box);
QCheckBox* c4 = new QCheckBox(wid);
c4->setGeometry(80,5,50,40);
c4->setBackgroundColor(QColor(100, 0,255));

-----
Also I can't change the width of purple...and now I don't use layout (only this code)

wysota
2nd April 2006, 11:50
Maybe it would be easier to subclass QButton and provide a custom paintEvent for it? One that would use QStyle::drawControl() and QStyle::drawPrimitive() with CE_CheckBox and PE_CheckMark respectively.

mickey
2nd April 2006, 12:56
Beyond the setGeometry problem, how you can see in first attach, checkBox and QLabel named 'l0' aren't verticallly aligned; Why this? I use QVboxLayout but the align isn't perfect
Thanks