How to set QWidget
width? I know setGeometry(QRect& rect)
function to do that, but in that case I should use geometry()
function to get former parameters of my QWidget
, then I should increment the width and use setGeometry(..). Is there any direct way to that, say:
QWidget aa; aa.setWidth(165); //something like this?
If the width won't change afterwards, you can use setFixedWidth : widget->setFixedWidth(165); Similarly, to change the height without changing the width, there is setFixedHeight . Never use fixed width!
The QWidget class is the base class of all user interface objects.
Widgets are the primary elements for creating user interfaces in Qt. Widgets can display data and status information, receive user input, and provide a container for other widgets that should be grouped together. A widget that is not embedded in a parent widget is called a window.
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.
resize()
might be better to use.
Example usage:
widget->resize(165, widget->height());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With