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. QDialog doesn't stay on top....
Forum Updated to NodeBB v4.3 + New Features

QDialog doesn't stay on top....

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 2.4k 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.
  • D Offline
    D Offline
    Dosfried
    wrote on last edited by
    #1

    Hi,

    i have a problem where i show a modeless dialog in which the User has the ability to pick a color from a control within the main window.
    On PC1(My development PC) it works as expected. On PC2 it behaves much different. When i click anywhere outside the dialog, it gets hidden behind the MainWindow. In the documentation it says ". A dialog is always a top-level widget...", that doesn't seem to be the case.
    I already tried to set the WindowStaysOnTopHint inside the Dialog constructor, but it doesn't change anything.

    This is how i initialize the Dialog:

    m_recordDialog = new RecordDialog(this);
    

    And this is how i present it:

    m_recordDialog->show();
    

    I'm using Qt 5.12.2(x64) and Visual Studio 2015.

    Dosfried

    jsulmJ 1 Reply Last reply
    0
    • D Dosfried

      Hi,

      i have a problem where i show a modeless dialog in which the User has the ability to pick a color from a control within the main window.
      On PC1(My development PC) it works as expected. On PC2 it behaves much different. When i click anywhere outside the dialog, it gets hidden behind the MainWindow. In the documentation it says ". A dialog is always a top-level widget...", that doesn't seem to be the case.
      I already tried to set the WindowStaysOnTopHint inside the Dialog constructor, but it doesn't change anything.

      This is how i initialize the Dialog:

      m_recordDialog = new RecordDialog(this);
      

      And this is how i present it:

      m_recordDialog->show();
      

      I'm using Qt 5.12.2(x64) and Visual Studio 2015.

      Dosfried

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

      @Dosfried said in QDialog doesn't stay on top....:

      m_recordDialog->show();

      you can use exec() instead of show() if you want your dialog to block everything else, then it will be always on top.

      Else you can set Qt::WindowStaysOnTopHint via https://doc.qt.io/qt-5/qwidget.html#setAttribute

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

      JonBJ 1 Reply Last reply
      1
      • jsulmJ jsulm

        @Dosfried said in QDialog doesn't stay on top....:

        m_recordDialog->show();

        you can use exec() instead of show() if you want your dialog to block everything else, then it will be always on top.

        Else you can set Qt::WindowStaysOnTopHint via https://doc.qt.io/qt-5/qwidget.html#setAttribute

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @jsulm
        The trouble is the OP states:

        I already tried to set the WindowStaysOnTopHint inside the Dialog constructor, but it doesn't change anything.

        And he wants modeless, so not exec().

        @Dosfried
        I am interested in whether you really do find this behaviour. I am currently having to work on modeless/stay on top, but I only have access to Linux where it does behave differently from Windows which I also have to support! It should not just be different across different PCs AFAIK. Are they running the same Windows version? Is there some other difference?

        jsulmJ 1 Reply Last reply
        1
        • JonBJ JonB

          @jsulm
          The trouble is the OP states:

          I already tried to set the WindowStaysOnTopHint inside the Dialog constructor, but it doesn't change anything.

          And he wants modeless, so not exec().

          @Dosfried
          I am interested in whether you really do find this behaviour. I am currently having to work on modeless/stay on top, but I only have access to Linux where it does behave differently from Windows which I also have to support! It should not just be different across different PCs AFAIK. Are they running the same Windows version? Is there some other difference?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @JonB Need to read more carefully :-)

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

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dosfried
            wrote on last edited by
            #5

            First of all thanks for the fast reply's. I really appreciate it.

            @jsulm
            I cannot use exec, because my dialog needs to be modeless. Otherwise i cannot use the color picker functionality from my RecordDialog class.
            I already tried setting this flag. It doesn't make any difference...

            @JonB
            What do you mean by "I am interested in whether you really do find this behaviour."
            I am definitely getting this behavior on different machines here at work.

            On my desktop pc everything works as expected. On my co workers laptop everything works as expected.
            But on the Laptop where the software should finally run, it is acting strange...

            Every computer which i tried runs Windows 10 (Either Home or Enterprise)

            JonBJ 1 Reply Last reply
            0
            • D Dosfried

              First of all thanks for the fast reply's. I really appreciate it.

              @jsulm
              I cannot use exec, because my dialog needs to be modeless. Otherwise i cannot use the color picker functionality from my RecordDialog class.
              I already tried setting this flag. It doesn't make any difference...

              @JonB
              What do you mean by "I am interested in whether you really do find this behaviour."
              I am definitely getting this behavior on different machines here at work.

              On my desktop pc everything works as expected. On my co workers laptop everything works as expected.
              But on the Laptop where the software should finally run, it is acting strange...

              Every computer which i tried runs Windows 10 (Either Home or Enterprise)

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @Dosfried

              What do you mean by "I am interested in whether you really do find this behaviour."
              Every computer which i tried runs Windows 10 (Either Home or Enterprise)

              I meant that, especially since you say they are now all running the same Windows, I really don't think you should be finding they exhibit different behaviour. Either they should all have it on top, or none of them should have it on top, but you should not be seeing some with one behaviour and some with the other. Ultimately I would expect the Qt code to set some native Windows flag for the behaviour, and that should behave consistently.

              What about creating an absolutely minimal example for your code/behaviour and then posting it here if you find different behaviour so that others can test?

              1 Reply Last reply
              1
              • D Offline
                D Offline
                Dosfried
                wrote on last edited by Dosfried
                #7

                Okay i think i narrowed it down quite a bit.
                I am only experiencing this behaviour when i am using a QOpenGLWidget inside my MainWindow and the Computer only has an integrated graphics card....

                Here is a minimal example.

                // main.cpp
                #include "MainWindow.h"
                #include <QApplication>
                
                int main(int argc, char* argv[])
                {
                    QApplication application(argc, argv);
                    MainWindow window;
                    window.showFullScreen();
                    return application.exec();
                }
                
                //MainWindow.h
                #pragma once
                
                #include <QMainWindow>
                #include "ui_MainWindow.h"
                
                class MainWindow : public QMainWindow
                {
                    Q_OBJECT
                
                public:
                
                    MainWindow(QWidget* parent = nullptr);
                
                private slots:
                
                    void onAction();
                
                private:
                
                    Ui::MainWindow m_form;
                    QOpenGLWidget* m_glWidget;
                    QDialog*       m_dialog;
                };
                
                //MainWindow.cpp
                #include "MainWindow.h"
                #include <QAction>
                #include <QDialog>
                #include <QOpenGLWidget>
                
                MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
                {
                    m_form.setupUi(this);
                
                    m_glWidget = new QOpenGLWidget(this);
                
                    setCentralWidget(m_glWidget);
                
                    QAction* dialogAction = new QAction("Open Dialog", this);
                    connect(dialogAction, &QAction::triggered, this, &MainWindow::onAction);
                
                    m_form.toolBar->addAction(dialogAction);
                
                    m_dialog = new QDialog(this);
                }
                
                void MainWindow::onAction()
                {
                    m_dialog->show();
                }
                

                Can anybody confim this?

                1 Reply Last reply
                2

                • Login

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