Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set user data for a QWidget?

Tags:

I would like to set an integer number to be stored in a QWidget, and I think the setUserData member function would do the trick but I can't find any documentation. Any hints?

like image 770
Barney Szabolcs Avatar asked Oct 22 '12 19:10

Barney Szabolcs


People also ask

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.

Is QWidget a QObject?

All Qt widgets inherit QObject. The convenience function isWidgetType() returns whether an object is actually a widget. It is much faster than qobject_cast<QWidget *>(obj) or obj->inherits("QWidget"). Some QObject functions, e.g. children(), return a QObjectList.

How do I change my QWidget position?

Use QWidget::move() to set the position, QWidget::resize() to set the size and reimplement the parent's resizeEvent() handler if you need to re-position the widgets if their parent resizes. Show activity on this post. You just need to create your widget, indicate its parent QWidget and then display it.


1 Answers

You might be looking for QObject::setProperty() (which is of course inherited by QWidget).

like image 116
Frédéric Hamidi Avatar answered Sep 27 '22 19:09

Frédéric Hamidi