PDA

View Full Version : QLabel or any Widget Resize Itself, how to disable.



vitaR
29th June 2014, 01:51
Hi, I have a problem that is so annoying. Already searched so many post but still don't figure out how to solve.

I have a QLabel in a QMainWindow, the problem is that everytime I add this Label to the window (using setCentralWidget),
the QLabel takes the whole unused space of the window. The QLabel Resize itself and takes the whole space.

I tried to use setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixe d); but didnt work.

By the way, there is other question, can I add as many Labels, buttons in a Container without using layouts?
something like, Table(Draughts), and the table can be the container of anything? I mean setting specific positions without having my first problem? (The Resize issue).

ChrisW67
29th June 2014, 03:45
The central widget of a QMainWindow always occupies all the available space inside the main window. If you want to decouple the size of the label from the size of the main window then you need to place it in a container with a suitable layout and spacers or other widget to occupy the "empty" space. Then set that container as the central widget.



By the way, there is other question, can I add as many Labels, buttons in a Container without using layouts?

Yes. Make the labels, buttons, etc. children of the container widget and they will appear inside and on top of the container.. You will need to position, size and resize them manually.

IMHO, if you think you need to manually place large numbers of widgets then you are almost certainly thinking about your problem the wrong way.

vitaR
29th June 2014, 21:15
The container have an specific data type or is just a QWidget called container?
Can you show me example? sorry I'm so new on this.

label = new QLabel("Test");
label->setMinimumSize(60,60);
container = new QWidget(label);
setCentralWidget(container);

Its this ok?
And thanks.

anda_skoa
29th June 2014, 21:44
Container can be any widget, but usually it is just a QWidget, a QFrame or a QGroupBox.
In your case a QWidget is sufficient.

Your code looks right for an unlayouted window.
Usually you don't want that at all, manual layouting is tedious.

Cheers,
_

vitaR
29th June 2014, 22:02
Container can be any widget, but usually it is just a QWidget, a QFrame or a QGroupBox.
In your case a QWidget is sufficient.

Your code looks right for an unlayouted window.
Usually you don't want that at all, manual layouting is tedious.

Cheers,
_

Thanks but, this doesn't show my QLabel on the window. And there's a method to add the QLabel without sending throw the constructor of the QWidget?

ChrisW67
30th June 2014, 03:49
The widget "container" should be the parent of "label", not the other way around.

vitaR
30th June 2014, 06:14
Thanks everyone for your answers. I like this forum :)