How can I programmatically add QPushButtons in a QFrame without using Layout?
Hi,
I add qpushbuttons on Form and set my buttons' positions with setGeometry. It's ok.
Now I want to divide these buttons into QFrame as the groups.
I add buttons on Form as follow:
myBtn[btn]=new QPushButton(this);
myBtn[btn]->setGeometry(intWidth*i,y,intWidth,intWidth);
How can I add these buttons into QFrame? VBoxLayout, HBoxLayout or GridLayout is not suitable for my buttons' position.
So I don't want to use layout.
Thanks.
Re: How can I programmatically add QPushButtons in a QFrame without using Layout?
Make your push buttons child of QFrame.
Code:
myBtn[btn]->setGeometry(intWidth*i,y,intWidth,intWidth);
Now setGeometry will set the push button positions with respect to its parent QFrame.
Re: How can I programmatically add QPushButtons in a QFrame without using Layout?
Not using a layout is usually a bad idea. Are you having such a dynamic situation that you need to move the buttons a lot?
In any case, I don't quite understand your problem.
Layouts don't add widgets to frames, they manage the size and location within the parent widget, whether that is a frame or some other widget.
Cheers,
_
1 Attachment(s)
Re: How can I programmatically add QPushButtons in a QFrame without using Layout?
Thanks for your quick replay.
Now I save my button locations and sizes in struct array with map number.
I place freely these buttons with maps without any layout.
QFrame frame = new QFrame(this);
myBtn[btn]=new QPushButton(frame);
myBtn[btn]->setGeometry(intWidth*i,y,intWidth,intWidth);
It's OK.
Thanks anda_skoa for your suggestion.
I also think "Not using a layout is usually a bad idea". But I can't decide which type of layout should I use to add there buttons on the Form according to my maps?
Attachment 11577
Please see picture of my button position and size. It's a map number 1.
There are many maps to place buttons. Number of buttons and locations are different for maps.
Thanks
Re: How can I programmatically add QPushButtons in a QFrame without using Layout?
Quote:
Please see picture of my button position and size. It's a map number 1.
There are many maps to place buttons. Number of buttons and locations are different for maps.
What is a "map"? Is it a button or is it a container (widget) where you want to place one or more buttons?
Re: How can I programmatically add QPushButtons in a QFrame without using Layout?
I want to add 7 buttons (please see above my post). The buttons' positions and sizes are shown at picture ( I named a group of buttons' sizes and positions as a map).
Which layout can I use to place buttons on a Form?
Thanks.
Re: How can I programmatically add QPushButtons in a QFrame without using Layout?
You should be using a QGridLayout.
Especially rowSpan and columnSpan with the alignment should be sufficient to get the widgets as shown in your image.
Code:
void QGridLayout::addWidget(QWidget * widget,
int fromRow,
int fromColumn,
int rowSpan,
int columnSpan, Qt
::Alignment alignment
= 0)