You are not logged in.

Dear visitor, welcome to If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.


Friday, November 4th 2011, 6:12pm

Custom widget with dynamic properties

I am trying to write some set of custom widget as Qt Designer plugin. Some of the properties are same for all my widgets, so I want to make a base class. But there is a problem with multiple inheritnece, when base class inherits from QObject (because of Q_PROPERTY macro to make its properties editable in Qt Designer) and the custom widget needs to be child of QWidget. But I found Qt's dynamic property so base class gets the widget pointer and sets the dynamic property.

Source code

class BaseClass {
  QWidget *widget;
  BaseClass(QWidget *widget) {
    this->widget = widget;
    this->widget->setProperty("Some", 0.0);
  void setSome(double some) {
    this->widget->setProperty("Some", some);

Thats ok. I can set the dynamic property and see them and edit them in Qt Designer, all is ok. BUT when I want to read from the property something is wrong. When I am using:

Source code


Qt Designer doesn't start (?!).

And when I use this more then once

Source code

  QVariant var = this->widget->property("Some");
  return var.toDouble();

It's the same problem! Qt Designer fails to start with no message or other hint. I am using Qt 4.7.4 with its designer. The same proble is in Qt Creators designer (tested on 2.0.0, 2.0.1).

Am I wrong or it is Qt's issue?

Thanks for any suggestions!

This post has been edited 1 times, last edit by "tomicious" (Nov 5th 2011, 6:57am)


Wednesday, November 9th 2011, 3:17pm

Problem solved, I've rewritten the 'Derived' and it's working now. Some C++ magic was probably there.