Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Creating double Widgets
FleeXo last edited by FleeXo
Im very new to Qt. Now I followed the Qt Code Editor Example and wanted adapt this example to an ui form. But now it is getting
created twice. Once with the right logic and once just blank.
Maybe someone can help me and teach me what I am doing wrong.
I would really appreciate it.
Here are the sources: https://github.com/tzAcee/qt_IDE Everything about the editor is in the editor.cpp/.h
Hi and welcome to the forums
Your custom editor is also a PlainTextWidget so i think maybe you were meant to use the promotion feature
to have that editor in UI become your custom widget/editor
The code you have simply create a new Editor and use the existing
"Editor" as parent.
QPlainTextEdit a = ui->centralwidget->findChild<QPlainTextEdit>("editor");
_editor = new Editor(a);
This just create a new one. And as you see is put inside the Editor you already have on UI form.
Lets try Promotion. ( which is a Creator feature that lets you use custom widgets)
// QPlainTextEdit a = ui->centralwidget->findChild<QPlainTextEdit>("editor");
// _editor = new Editor(a);
go to Editor.H, ctor
Editor(QPlainTextEdit *parent = nullptr);
This says parent will be QPlainTextEdit but that wont work. so
Change it to
Editor(QWidget *parent = nullptr);
also change in .CPP ! ( Editor::Editor(QWidget *parent) : QPlainTextEdit(parent) )
Then go to Mainwindow.ui
right click the Editor widget and select "Promote To" menu item
Then add the info (editor.h and Editor)
and press ADD
Then Press Promote
Then Press oK
Then rebuild all
and now when you run the Widget in UI becomes your custom widget
Hope this explains well enough, else ask :)
FleeXo last edited by
@mrjj Thank you very much it just works fine.
The hint with the promoting feature was just amazing!
The docs just in case
Also note we have dynamic properties.
So you can add new properties in Designer and read at runtime in code.
That makes it possible to be able to tweak custom widgets design time without having to write a full-blown
plugin to have them truly as custom widgets as the other std. widgets.
I love the Promotion feature and use alot :)
FleeXo last edited by
@mrjj I will definitly give it a try, thank you :)