Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Creating a form at runtime
Forum Updated to NodeBB v4.3 + New Features

Creating a form at runtime

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.0k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    dolevo
    wrote on 1 May 2014, 18:16 last edited by
    #1

    Hi guys,

    I create a form at runtime like the following:

    @ QWidget *form=new QWidget(this);
    QGridLayout *lay = new QGridLayout();

        lay->addWidget(new QLabel("Select a User:"), 0, 0);
        QStringList userlist = db->mpRetrieveUserColumn("username");
        userSelectComboBox = new QComboBox();
        foreach(QString str, userlist)
            userSelectComboBox->addItem(str);
        lay->addWidget(userSelectComboBox, 0, 1, 1, 2);
    
        QPushButton *btn = new QPushButton("OK");
        connect(btn, SIGNAL(clicked()), this, SLOT(mpOnUserSelected()));
        lay->addWidget(btn, 2, 2);
        form->setLayout(lay);
        form->show();@
    

    I call this in the main thread where I have the ui. However, this show the widget on the existing form. However, I want to have this form like a new modal form on top of the main form. I have been looking into the documentation but couldn't find it yet. Could you please give me a hint?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on 1 May 2014, 18:38 last edited by
      #2

      Try using, e.g., a QDialog instead of QWidget if you want a top-level widget. You could also use QWidget and specify NULL as parent in the constructor.

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dolevo
        wrote on 1 May 2014, 18:46 last edited by
        #3

        [quote author="MuldeR" date="1398969507"]Try using, e.g., a QDialog instead of QWidget if you want a top-level widget. You could also use QWidget and specify NULL as parent in the constructor.[/quote]

        My Lord,
        Awesome! I never thought about giving NULL parameter but it make a lot sense. Thanks a lot.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MuldeR
          wrote on 1 May 2014, 19:04 last edited by
          #4

          The manual is quite explicit about this ;-)

          If parent is 0, the new widget becomes a window. If parent is another widget, this widget becomes a child window inside parent.

          My OpenSource software at: http://muldersoft.com/

          Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

          Go visit the coop: http://youtu.be/Jay...

          1 Reply Last reply
          0

          1/4

          1 May 2014, 18:16

          • Login

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