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

How to set modality to QWidget

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 5 Posters 11.0k Views 3 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.
  • F Offline
    F Offline
    Fulgurance
    wrote on last edited by Fulgurance
    #1

    Hello, i'm working actually into software, and i need to set modality for class inherit to QWidget, because i wouldn't like user can input into previous Widget

    Is it mandatory and better to inherit to QDialog?

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      You can edit the QWidget's windowModality property: https://doc.qt.io/qt-5/qwidget.html#windowModality-prop

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

      1 Reply Last reply
      2
      • F Offline
        F Offline
        Fulgurance
        wrote on last edited by
        #3

        Yes,i have seen that, but when i do setWindowModality(Qt::WindowModal);, nothing, the previous window is available.

        Look:

        void MainWindow::initialize()
        {
            setWindowTitle("Caisse");
            //setWindowIcon(QIcon(""));
            setWindowFlags(Qt::WindowMinimizeButtonHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
            setWindowModality(Qt::WindowModal);
            initialize_pointers();
            setLayout(main_layout);
        }
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Without the rest of the code it's going to be difficult find what is going wrong.

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

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

            Hi
            You can also use
            setWindowModality(Qt::ApplicationModal);

            1 Reply Last reply
            2
            • F Offline
              F Offline
              Fulgurance
              wrote on last edited by
              #6

              Oh yes perfect! Thanks you very much!

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

                @JKSH
                Hi
                while we talk about Qt::WindowModality
                Since have to give a QWidget no parent to have be a window, how would
                setWindowModality(Qt::WindowModal);
                Be able to work as it has no parent then?
                Do you know the secret :) ?

                JKSHJ B 2 Replies Last reply
                0
                • mrjjM mrjj

                  @JKSH
                  Hi
                  while we talk about Qt::WindowModality
                  Since have to give a QWidget no parent to have be a window, how would
                  setWindowModality(Qt::WindowModal);
                  Be able to work as it has no parent then?
                  Do you know the secret :) ?

                  JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #8

                  @Fulgurance said in How to set modality to QWidget:

                  Oh yes perfect! Thanks you very much!

                  Great! Happy coding :)

                  @mrjj said in How to set modality to QWidget:

                  while we talk about Qt::WindowModality
                  Since have to give a QWidget no parent to have be a window, how would
                  setWindowModality(Qt::WindowModal);
                  Be able to work as it has no parent then?
                  Do you know the secret :) ?

                  Ha! I didn't even think about that.

                  Qt::WindowModal is probably useless for widgets that don't inherit QDialog.

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

                  1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @JKSH
                    Hi
                    while we talk about Qt::WindowModality
                    Since have to give a QWidget no parent to have be a window, how would
                    setWindowModality(Qt::WindowModal);
                    Be able to work as it has no parent then?
                    Do you know the secret :) ?

                    B Offline
                    B Offline
                    Bonnie
                    wrote on last edited by Bonnie
                    #9

                    @mrjj
                    Actually a QWidget can be a window and have a parent at the same time.
                    It just need to have Qt::Window flag set.
                    And it acts similar to a QDialog (which also have Qt::Window flag) with a parent.

                    JKSHJ 1 Reply Last reply
                    2
                    • B Bonnie

                      @mrjj
                      Actually a QWidget can be a window and have a parent at the same time.
                      It just need to have Qt::Window flag set.
                      And it acts similar to a QDialog (which also have Qt::Window flag) with a parent.

                      JKSHJ Offline
                      JKSHJ Offline
                      JKSH
                      Moderators
                      wrote on last edited by
                      #10

                      @Bonnie said in How to set modality to QWidget:

                      Actually a QWidget can be a window and have a parent at the same time.
                      It just need to have Qt::Window flag set.
                      And it acts similar to a QDialog (which also have Qt::Window flag) with a parent.

                      Well-spotted. Thanks!

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

                      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