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
Forum Updated to NodeBB v4.3 + New Features

How to set modality to QWidget

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 5 Posters 8.4k 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 2 Aug 2020, 07:03 last edited by Fulgurance 8 Feb 2020, 07:06
    #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
    • J Online
      J Online
      JKSH
      Moderators
      wrote on 2 Aug 2020, 07:17 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 2 Aug 2020, 07:41 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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 2 Aug 2020, 09:00 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
          • M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 2 Aug 2020, 10:19 last edited by
            #5

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

            1 Reply Last reply
            2
            • F Offline
              F Offline
              Fulgurance
              wrote on 2 Aug 2020, 13:31 last edited by
              #6

              Oh yes perfect! Thanks you very much!

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 2 Aug 2020, 13:40 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 :) ?

                J B 2 Replies Last reply 2 Aug 2020, 23:11
                0
                • M mrjj
                  2 Aug 2020, 13:40

                  @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 :) ?

                  J Online
                  J Online
                  JKSH
                  Moderators
                  wrote on 2 Aug 2020, 23:11 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
                  • M mrjj
                    2 Aug 2020, 13:40

                    @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 2 Aug 2020, 23:41 last edited by Bonnie 8 Mar 2020, 00:11
                    #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.

                    J 1 Reply Last reply 3 Aug 2020, 01:20
                    2
                    • B Bonnie
                      2 Aug 2020, 23:41

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

                      J Online
                      J Online
                      JKSH
                      Moderators
                      wrote on 3 Aug 2020, 01:20 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

                      1/10

                      2 Aug 2020, 07:03

                      • Login

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