Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How to code QT "dialog" wihtout using QTDesigner "form"?
Forum Update on Monday, May 27th 2025

How to code QT "dialog" wihtout using QTDesigner "form"?

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
3 Posts 2 Posters 364 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    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 QTDesigner

    https://forum.qt.io/topic/36768/resolved-create-a-base-project-to-show-a-simple-dialog-starting-from-an-empty-project

    It 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.

    JonBJ 1 Reply Last reply
    0
    • A Anonymous_Banned275

      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 QTDesigner

      https://forum.qt.io/topic/36768/resolved-create-a-base-project-to-show-a-simple-dialog-starting-from-an-empty-project

      It 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.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @AnneRanch
      Anything you can do in Designer can be done in code. When you build Qt runs its uic processor on your .ui file to generate a ui_.....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 a QDialog, 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.

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved