1

I want to create custom widget with ui form, but if I add ui form to the widget, it is not showing when building widget.

Shortly, I want to add one button and one textedit into a ui form, and create a custom widget with that, is there an example like this, or how do I do it?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • you mean add in editor or add at runtime?? – ΦXocę 웃 Пepeúpa ツ Jul 23 '20 at 07:35
  • adding in editor for further use, I can add in editor a custom widget but I don't know how to implement an ui form like user control in visual studio, i want to create a form like widget and want to show in a QWidget in my main program. – Hüseyin Babuc Jul 23 '20 at 07:52
  • have you seen the examples that ship with Qt? You can [access them via Qt-Creator](https://doc.qt.io/qtcreator/creator-build-example-application.html). You must initialize and attach the GUI to the widget manually. [here is another nice tutorial](https://doc.qt.io/qtcreator/creator-writing-program.html). – pasbi Jul 23 '20 at 09:29

1 Answers1

2

It is very simple to create your custom widget and add it to your ui form. Just follow this:

1- Create a default Qt Widgets Project width ui form.

2- Right click on youe project in Projects window and click 'Add New'

3- Select 'C++ Class' and click 'Choose...'

4- Enter your custom widget name and select "QWidget" as "Base class" and click "Next' and then 'Finish'.

5- In the form editor, add a Widget to the form and then right click on it.

6- From the popup menu , select "Promote to..."

7- In dialog that is displayed, enter your custom widget name in the "promoted class name" field and click add.

8- Select custom widget from list and click "promote"

Ali Askari
  • 515
  • 3
  • 8