qproperty

Dump all properties of a QObject derived object

只谈情不闲聊 提交于 2021-02-07 06:48:22
问题 How to dump all properties of a Qt object? For debugging purpose, e.g. when analyzing objects returned by a factory. 回答1: Properties of objects derived from QObject are registered via Qt's meta object system. Thus, it can be used to introspect them, i.e. list all properties and their content, e.g.: #include <QDebug> #include <QMetaProperty> #include <vector> #include <utility> #include <algorithm> static void dump_props(QObject *o) { auto mo = o->metaObject(); qDebug() << "## Properties of" <

Parsing property values from stylesheet for drawing custom widgets

一笑奈何 提交于 2021-02-05 11:20:07
问题 I have to create a couple of custom qt widgets, some of which use custom drawing. Those widgets should be styled via the companies qt stylesheet. This creates the problem that some custom widget need to retrieve a value from stylesheet that has been applied to the QMainWindow or QApplication . This value could either be one of qt's official properties or some custom qproperty-... property However, it is not trivial to access them from the widget. One option would be to get the stylesheet

Using an existing Q_PROPERTY to animate QGraphicsItem inheriting QObject

笑着哭i 提交于 2020-01-07 05:34:08
问题 I have 2 classes, one MainWindow in which we draw in a QGraphicsView a circle (which intend to become a button !) created thanks to an other class. The class MyCircle inherits from QObject and QGraphicsItem since I want to make animation. My issue is the following : My goal is first to make a simple animation on my drawing : make it smaller then it goes back to the original size. So I suppose I should use the property geometry, already existing in the QObject class. To do this I write in my

How to override a Q_Property?

别说谁变了你拦得住时间么 提交于 2019-12-24 07:46:28
问题 Consider these classes: Class A : public QObject { ... Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged) virtual int value() { return m_value; } void setValue(int v) { m_value = v; Q_EMIT valueChanged();} ... }; Class B : public A { ... int value() { return m_value * 2; } ... }; When property value is accessed, the Class A method is called directly instead of Class B's. So far, to workaround this apparent limitation I've replicated the property code and connected the signals

For a NOTIFY signal on a property, what difference does it make if I give it a parameter?

时光怂恿深爱的人放手 提交于 2019-12-11 08:41:47
问题 Suppose I have a class that looks like this: class Something : QObject { Q_PROPERTY(int something READ getSomething NOTIFY somethingChanged) // ... signals: void somethingChanged(); } According to the documentation, declaring somethingChanged as void somethingChanged() and void somethingChanged(int) (note the parameter) are both valid. Why would I want to do it one way over the other? 回答1: Emitting the value allows you to use that value without having a reference to the object it is a

How to animate color of QBrush

元气小坏坏 提交于 2019-12-06 07:36:39
问题 I want to animate Color of QBrush . For more details see code below That's my .h file class Cell : public QObject, public QGraphicsRectItem { Q_OBJECT Q_PROPERTY(QBrush brush READ brush WRITE set_Brush) public: QBrush _brush() const; void set_Brush(const QBrush&); Cell(QGraphicsItem *parent = 0); //конструктор } That's my .cpp file Cell::Cell(QGraphicsItem *parent) : QObject(), QGraphicsRectItem(parent) { this->setRect(0, 0, Scale, Scale); } QBrush Cell::_brush() const { return this->brush();