简体   繁体   中英

how to add a custom widget to Qt 4.8.6

I'm trying to figure out how to add a custom widget to Qt Designer. So far I've been unsuccessful. Very new to Qt. I'm running Qt 4.8.6. I know there is a newer version but due to project constraints I have to stick with this one. Essentially I'm need to add a hex spin box, ie a spinbox that counts in hex rather than in decimals. I even found code that implements it . It does explain how to integrate it into Qt Designer , however it is explained for version 3. Can someone offer assistance?

Any help is greatly appreciated

Read about creating designer widgets and using them , but briefly:

  • Subclass QDesignerCustomWidgetInterface to create your custom designer plugin for your custom widget
  • Build and install your designer plugin
  • Tell designer about your plugin location, or just make sure it's installed to $QTDIR/plugins/designer

There's also an example to follow.

Here is a documentation. At short, you just add any widget (eg QSpinBox to draw it nice in the Designer) to your form and convert it to the needed one.

To add a custom widget to Qt designer simply follow the steps:

  1. In Qt designer create a new widget File->New->Widget.
  2. Add your UI etc for this widget and save it->->MyWidget.ui
  3. Create a class "MyWidgetHandler" to handle this widget in a MyWidgetHandler.h & cpp
  4. In your MainWindow/Dialog wherever you want to display this widget add a "Widget" from the "Containers" section of the designer.

    在此处输入图片说明

  5. Now right-click the "Widget" container you just added and click "Promote to..."

  6. This should open a dialog. You can select here the base class to inherit properties in your case QComboBox or just select the QWidget class.
  7. Next enter the full class name ie with namespaces eg: "blah::MyWidgetHandler"
  8. In the Header file section simply add the path to the header file for this class. This should be a resolvable path. Eg: "UI/MyWidgetHandler.h" or "C:/UI/MyWidgetHandler.h"
  9. Now click "Promote" and save your MainWindow.ui
  10. The Property Editor should now show your custom class type eg: blah::MyWidgetHandler. and the properties from the base class you selected.
  11. Don't forget to setup the UI in your handler class and include header in the Mainwindow handler.

Cheers !!!

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