Unsolved How to code QT "dialog" wihtout using QTDesigner "form"?
-
I do not know how else to say this -
I have an example project which APPEARS to create dialog WITHOUT using the QTDesiger "form". - the actual form seems to be coded .
I understand it is perfectly legal , but I cannot figure it out , in the existing code , how it is done.Mrs Google is of no help.
This describes standard - create project using QTDesignerIt would,l help me to have both dialog object with QTDesiigner form - standard - and another object where the "form " is done in code. - just to compare.
Any constructive help would be appreciated. -
@AnneRanch
Anything you can do in Designer can be done in code. When you build Qt runs itsuic
processor on your.ui
file to generate aui_.....h
file from it, which is C++ source code that is then compiled, so everything just comes down to code which you can write without Designer.About the simplest
QDialog
code would look like:#include <QApplication> #include <QDialog> #include <QLabel> #include <QLayout> #include <QPushButton> int main(int argc, char *argv[]) { QApplication a(argc, argv); QDialog dialog; dialog.setGeometry(100, 100, 400, 400); QVBoxLayout layout; dialog.setLayout(&layout); QLabel label("This is a label"); layout.addWidget(&label); QPushButton button("This is a button"); layout.addWidget(&button); dialog.exec(); }
About the simplest example I could find among those supplied with Qt is https://doc.qt.io/qt-5/qtwidgets-tutorials-addressbook-part1-example.html. It uses a
QWidget
rather than aQDialog
, but it has the complete project including.pro
file at https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/tutorials/addressbook/part1?h=5.15. -
Thank you.
Your example will help me to figure out why a project which does not use QTDesigner to build the form won't compile as subdirs project.
My best guess it keeps "rebuilding " the form ( dialog) from code.