Resizing buttons in Layout
So,I'm making a Tic Tac Toe game and I'd like to put my buttons,like: 3 rows of 3 buttons.
So far I have this:
Code:
hl1->addWidget(btn[0]);
hl1->addWidget(btn[1]);
hl1->addWidget(btn[2]);
hl2->addWidget(btn[3]);
hl2->addWidget(btn[4]);
hl2->addWidget(btn[5]);
hl3->addWidget(btn[6]);
hl3->addWidget(btn[7]);
hl3->addWidget(btn[8]);
vl1->addLayout(hl1);
vl1->addLayout(hl2);
vl1->addLayout(hl3);
win->setLayout(vl1);
TicTacToe::setCentralWidget(win);
But buttons here have the normal size..how can I make then be square?
Thank you.
Re: Resizing buttons in Layout
QButton default Horizontal Policy is Minimum and the Vertical Policy is Fixed. Try to change the sizePolicy property with QSizePolicy::Expanding or whatever you like, for example button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)
Re: Resizing buttons in Layout
A QGridLayout might be a good fit for this also.
Re: Resizing buttons in Layout
Quote:
Originally Posted by
viulskiez
QButton default Horizontal Policy is Minimum and the Vertical Policy is Fixed. Try to change the sizePolicy property with QSizePolicy::Expanding or whatever you like, for example button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)
Yeah,thanks that worked.
But now what I have is a window with buttons all over it(I mean,when I resize window,the layout keeps growing...),but what I want,is to make the buttons on the one side(like make the layout ungrowable!) and some other widgets on the other side,outside the layout...
Re: Resizing buttons in Layout
btn[0]->setGeometry(150,260,150,35);
...
setFixedSize(400, 400);
Re: Resizing buttons in Layout
This doesn't help me...it keeps resizing layout.
Re: Resizing buttons in Layout
Put the other stuff into your layout(s) and adjust the size policies, stretch factors and maximum sizes of the widgets to do sane things with extra space.
Re: Resizing buttons in Layout
U mean,to put the rests widgets to vl1?
Re: Resizing buttons in Layout
Yes, if that is the logical place for them. If not then you might need to nest your existing layout set into another horizontal box layout with more widgets to the right or left of the "grid" you have already.
Re: Resizing buttons in Layout