Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt set default width of a QWidget

Tags:

c++

qt

One of those days when you get stuck on something stupid. I've got the Min/Max width set, but it defaults to the Max width. I want it to default to the minimum width. How do I do this.

like image 624
nwnoga Avatar asked Aug 08 '13 18:08

nwnoga


People also ask

How is the size of Qt widgets determined?

Every qt widget has a sizeHint function. You can print the returned value of this function to see what it is, as done in the above code snippet. This value, according to the official document, is the “recommended size for the widget”. Of course, you cannot get anything by just reading this statement.

What is QWidget * parent?

The tree-like organization of QWidgets (and in fact of any QObjects ) is part of the memory management strategy used within the Qt-Framework. Assigning a QObject to a parent means that ownership of the child object is transferred to the parent object. If the parent is deleted, all its children are also deleted.

What is QWidget class window?

The QWidget class is the base class of all user interface objects.


1 Answers

I also had massive trouble understanding why there isn't a "set to this size, but don't fix the values" method. It's called resize, like this:

QWidget *widget= new QWidget();
label->resize(50,50);
like image 160
Kristoffer Ottosson Avatar answered Sep 19 '22 22:09

Kristoffer Ottosson