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. How to assemble and display a dialog box "on the fly"
Forum Update on Monday, May 27th 2025

How to assemble and display a dialog box "on the fly"

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 741 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.
  • cerrC Offline
    cerrC Offline
    cerr
    wrote on last edited by cerr
    #1

    Hi,

    I wonder how I can assemble and display a dialog with a QListWidget with items that can be checked with a checkbox (as in options to configure)
    So far I've tried this:

    int scaper::dialogShow(QWidget *parent) {
    ScaperDialog dialog(parent);
    dialog.show();
    

    where the ScaperDialog class looks like:

    ScaperDialog::ScaperDialog(QWidget *parent) :QDialog(parent) {
    list = new QListWidget(parent);
    item = new QListWidgetItem();
    list->setItemWidget(item,new QCheckBox("checkBox"));
    list->addItem(item);
    }
    void ScaperDialog::CheckAll(void){}
    void ScaperDialog::UncheckAll(void){}
    
    

    but nothing actiually shows up on invocation of dialogShow() what am I missing?
    Thanks!

    jsulmJ 1 Reply Last reply
    0
    • cerrC cerr

      Hi,

      I wonder how I can assemble and display a dialog with a QListWidget with items that can be checked with a checkbox (as in options to configure)
      So far I've tried this:

      int scaper::dialogShow(QWidget *parent) {
      ScaperDialog dialog(parent);
      dialog.show();
      

      where the ScaperDialog class looks like:

      ScaperDialog::ScaperDialog(QWidget *parent) :QDialog(parent) {
      list = new QListWidget(parent);
      item = new QListWidgetItem();
      list->setItemWidget(item,new QCheckBox("checkBox"));
      list->addItem(item);
      }
      void ScaperDialog::CheckAll(void){}
      void ScaperDialog::UncheckAll(void){}
      
      

      but nothing actiually shows up on invocation of dialogShow() what am I missing?
      Thanks!

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @cerr said in How to assemble and display a dialog with a QListWidget with items that can be checked with a checkbox (as in options to configure):

      but nothing actiually shows up on invocation of dialogShow() what am I missing?

      You're missing: show() is non blocking call and dialog is a local variable inside dialogShow, so as soon as dialogShow finishes dialog is destroyed. Use exec() instead of show().

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • cerrC Offline
        cerrC Offline
        cerr
        wrote on last edited by cerr
        #3

        You're missing: show() is non blocking call and dialog is a local variable inside dialogShow, so as soon as dialogShow finishes dialog is destroyed. Use exec() instead of show().

        Okay,

        Yes, now the Dialog is showing when I use dialog.exec(); in scaper::dialogShow() but it's tiny, i.e. no room to display anything and when I use the mouse to enlarge it, there's no sign of any QListWidget, so I set some parameters to resize it:

        ScaperDialog::ScaperDialog(QWidget *parent) :QDialog(parent) {
            int nWidth = 300;
            int nHeight = 300;
            resize(nWidth, nHeight);
        

        but still no sign of a QListWidget, so I gave it a size too, just like:

            int WidX = 100;
            int WidY = 100;
        
            list = new QListWidget(parent);
            list->setBaseSize(WidX,WidY);
        

        I still see nothing inside the Dialog....what else am I missing?
        Thanks!

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @cerr said in How to assemble and display a dialog box "on the fly":

          list = new QListWidget(parent);

          Try with
          list = new QListWidget(this);

          cerrC 1 Reply Last reply
          2
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by SGaist
            #5

            Hi,

            You should put your dialog widgets in a layout. That will enable automatic sizing and positioning.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            cerrC 1 Reply Last reply
            2
            • mrjjM mrjj

              @cerr said in How to assemble and display a dialog box "on the fly":

              list = new QListWidget(parent);

              Try with
              list = new QListWidget(this);

              cerrC Offline
              cerrC Offline
              cerr
              wrote on last edited by cerr
              #6

              @mrjj said in How to assemble and display a dialog box "on the fly":

              Try with
              list = new QListWidget(this);

              Exactly, that's what I had wrong! I see it now...! :)

              1 Reply Last reply
              0
              • SGaistS SGaist

                Hi,

                You should put your dialog widgets in a layout. That will enable automatic sizing and positioning.

                cerrC Offline
                cerrC Offline
                cerr
                wrote on last edited by
                #7

                @SGaist said in How to assemble and display a dialog box "on the fly":

                Hi,

                You should put your dialog widgets in a layout. That will enable automatic sizing and positioning.

                Yup, that's what I'm working on next! :)

                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