0

I have a few custom widget that I promote from QWidget or QFrame, but I would like the constructor to be able to set a list of properties to fixed, and not have to change it in Qt Desigenr property list each time I add a one of these custom wdigets, for example in my CustomWidget class constructor :

this->setFrameShape(QFrame::NoFrame);

The problem is that those properties are applied after the constructor call in the generated ui.h file, which is generated from the designer's property list, e.g. for a default custom widget implementing QFrame:

frame = new CustomWidget(groupBox_17);
frame->setObjectName(QStringLiteral("frame"));
frame->setGeometry(QRect(40, 170, 101, 21));
frame->setFrameShape(QFrame::StyledPanel);
frame->setFrameShadow(QFrame::Raised);    

Here, we can see that the setFrameShape called in the generated file will override the setFrameShape in the custom widget's constructor since it is called afterwards.

So the only options I would see would be to call a method after the ui setup (which calls the generated ui.h file and therefore the setters) to change those properties like so :

ui->setupUi(this);
setComponentsProperties(); //Do my property changes here

Any idea to prevent the FrameShape property from CustomWidget from being overriden by the default property of QFrame set in Qt Designer, since I do not want to have to set this property by hand on every widget I will promote?

Dijdkay
  • 56
  • 1
  • 5
  • Please clarify what your problem is. You've shown what happens now, please show the code you expect to be generated when you have it your way. Please also describe what exactly you want Qt Designer to do *differently*. – Kuba hasn't forgotten Monica Aug 17 '16 at 13:42

1 Answers1

0

The properties are not overriden if they are truly defaults. Your .ui file is incorrect and explicitly overrides these properties. You should reset them to defaults and then the code you refer to won't be emitted. The setComponentProperties call is redundant, the code to set the properties belongs in your custom widget's constructor.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • When I put a new `QFrame` in my GUI with Qt Designer, the style is already set to `StyledPanel` in the property list, and the default button is already clickable. If I click it, it sets the property to `NoFrame`. Does it have anything to do with my options? – Dijdkay Aug 18 '16 at 06:15
  • Experiment. You might be seeing a Qt Designer bug. Edit the `.ui` file and remove any properties that are explicitly set on it. Alternatively, the class promotion should be set to `QWidget`, it then won't be applying any `QFrame`-related properties to it. Just because your class derives from `QFrame` doesn't mean you have to tell designer about that detail. – Kuba hasn't forgotten Monica Aug 18 '16 at 15:36