简体   繁体   中英

How to use custom widget in Qt-Designer

I want to use a custom widget in the GUI-Designer of Qt-Creator IDE. So i created a class which inherits from Qt's QWidget. It worked to place it on a QMainWindow programaticaly, but have to do my work in the desiger where it does not appear as an option in the kist of components.

I googled to find a solution for problem an found an manual on, who guesses, the Qt doc page ( https://doc.qt.io/archives/qt-4.7/designer-creating-custom-widgets.html and https://doc.qt.io/archives/qt-4.7/designer-creating-custom-widgets.html ). I tried to follow it but doesn't work.

Does someone know an other way to do this or can give a hint where i can search for problems following this tutorial?

Thanks in advance.

Codierknecht

If you are like me, the analog clock example didn't do it for you, in which case I found just one better tutorial. It may be on the kde site but I you dont need kde to do it, it just explains how to make the custom widget a plugin so you can add it into Qt Designer, rather than having to code it in, which is the norm when you just add a widget to your project and customize the class. I hope this page helps you like it helped me, get in the right direction of writing a single Qt Designer (or multiple) plugin:

Writing Qt Designer Plugins

If this link ever becomes dead, just do a search for the link itself, usually that will turn up the original page in someone's cache, as they do in the other examples above (the dead links in the above answers that just take you to main area and not to the pages originally intended).

There is a different example in the examples section of the Qt documentation that I think is a lot clearer.

Custom Widget Plugin Example

It was a little unclear to me when reading the tutorial where the Q_EXPORT_PLUGIN2() macro goes, but having full example code and project alleviates that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM