Is there a way to give promoted widgets properties in designer?
KidTrent last edited by
I've created a basic QTextEdit widget and promoted it to a custom version of QTextEdit (CustomTextEdit).
I'm okay with the visual updates not being available in Qt Designer, but I would ideally be able to set custom properties using Q_PROPERTY or something that Qt Designer allows me to adjust when it inherits from my custom CustomTextEdit class.
I tried adding a Q_PROPERTY but it had not effect.
Q_PROPERTY(QString fileName MEMBER m_file_name); Q_PROPERTY(QString sectionName MEMBER m_section_name);
Is there a way to make these properties available to Qt Designer or must I implement the Widget as a Custom Widget instead of a promoted one to achieve this?
You need to create a designer plugin.
Setting the property as dynamic property should work too.
JonB last edited by JonB
I have never done any of this Designer custom widget stuff --- too scary :) Do you mean setting as a dynamic property with promotion avoids having to create a Designer plugin?
avoids having to create a Designer plugin?
Simply try it out. But you have to know your properties by yourself while a simple designer plugin will provide them directly.
KidTrent last edited by KidTrent
@Christian-Ehrlicher Darn, I was hoping that wasn't the case. A dynamic property wouldn't be good in this situation because it's a property that I wanted automatically added to every widget derived of my class. Thanks for the response once again!
@JonB I guess if you're okay with creating a dynamic property every time you promote the widget manually... in that case probably. It's not as scary as you would think...
I did it for the first time yesterday and my notes were:
- It was a little finicky when it comes to finding the Plugins folder for designer... (I have to do it manually as it inserts it into the wrong directory).
- There should be better documentation that outlines the process using the Wizard and follows through to use of the plugin in external projects.
- The process could be much easier and more automated by Qt... For example when adding a custom widget using the designer to another project, Qt could/should automatically copy/move the .dll, .h, and .lib files and update the projects .pro file to have the required files included/loaded. This threw me off for probably an hour. Not sure why they haven't done this.
Just as a note for this
- that I wanted automatically added to every widget derived of my class.
You can also set up a promoted widget with all dynamic properties you want.
Then Drag it to back to the WidgetList so its shown in scratchpad.
Then you can use this as a template with all dynamic properties already added.
Simply drag it back into a from. Also works across projects if it also has the promoted widget included.
Make sure you hit a white empty area when dragging so it goes to scratchpad.