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. From QDialog to QWidget
Qt 6.11 is out! See what's new in the release blog

From QDialog to QWidget

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.1k Views 2 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.
  • S Offline
    S Offline
    Szabii
    wrote on last edited by Szabii
    #1

    Hi!

    I have a Main Menu based on QDialog. I can open several QDialogs from here but now, I need to create a QWidget, which can't be open the sam way as QDialogs. As we know, we can open a new QDialog with the following code:

    qdialogName variableName();
    variableName.setModal(true);
    variableName.exec();
    

    But now, as I said before, I have to open a QWidget window from my QDialog menu. I didn't find any solution for that, so I'd appreciate it if someone could help me with this. I tried the following code but didn't work (from my QDialog menu onButtonClick):

    qwidgetName variableName();
    variableName.setMOdal(true);
    variableName.exec();
    
    JKSHJ 1 Reply Last reply
    0
    • S Szabii

      Hi!

      I have a Main Menu based on QDialog. I can open several QDialogs from here but now, I need to create a QWidget, which can't be open the sam way as QDialogs. As we know, we can open a new QDialog with the following code:

      qdialogName variableName();
      variableName.setModal(true);
      variableName.exec();
      

      But now, as I said before, I have to open a QWidget window from my QDialog menu. I didn't find any solution for that, so I'd appreciate it if someone could help me with this. I tried the following code but didn't work (from my QDialog menu onButtonClick):

      qwidgetName variableName();
      variableName.setMOdal(true);
      variableName.exec();
      
      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @Szabii

      1. If your widget is a local variable in your function, it will be destroyed when the function returns.
      2. See the documentation for QWidget::show()

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      5
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by
        #3

        You need to understand that QDialog is a specialization of QWidget that has its own event loop. setModal isn't defined in QWidget as widgets simply post events to the main GUI event loop. QDialog is a bit different in that it has the appearance of running its own event loop, even if the implementation doesn't specifically do that. IOW, you don't exec() a regular widget.

        The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

        1 Reply Last reply
        3
        • S Offline
          S Offline
          Szabii
          wrote on last edited by
          #4

          Thanks, problem solved.

          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