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 implement three level window (Windows)
QtWS25 Last Chance

How to implement three level window (Windows)

Scheduled Pinned Locked Moved Unsolved General and Desktop
multiplewindowdialogswindows
2 Posts 2 Posters 267 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.
  • S Offline
    S Offline
    Sivan
    wrote on last edited by
    #1

    Hi all,

    I am trying to implement a dual screen application which should support 3 level (z-order) of windows.

    At the base, there is main widget and its aux widget which is created as child of main widget and placed in another screen. Some of the buttons in any of these widgets can open a dialog(mid level) that should always stay on top of this base level, but should not be a modal dialog. And that the same time, the base level or the mid level dialog can open a blocking dialog which should be the most top level.

    Below is a simplified example of my requirement.

    // Widget.h
    #pragma once
    
    #include <QWidget>
    
    class MainWidget : public QWidget
    {
        Q_OBJECT
    
    public:
        MainWidget(QWidget *parent = nullptr);
        ~MainWidget();
    
        virtual void setVisible(bool isVisible) override;
    
    private:
        QDialog* m_AuxDialog = nullptr;
        QDialog* m_Dialog = nullptr;
    };
    
    // Widget.cpp
    #include "widget.h"
    
    #include <QDialog>
    #include <QHBoxLayout>
    #include <QPushButton>
    
    class MidLevelDialog : public QDialog
    {
    public:
        explicit MidLevelDialog(QWidget* p_Parent = nullptr)
            : QDialog(p_Parent)
        {
            setWindowFlags(windowFlags() | Qt::Tool);
    
            auto hLayout = new QHBoxLayout(this);
            auto btn = new QPushButton("Open Modal Dialog", this);
    
            hLayout->addWidget(btn);
    
            connect(btn, &QPushButton::clicked, this, []{
                QDialog dlg;
                dlg.exec();
            });
        }
    
        virtual ~MidLevelDialog()
        {
        }
    };
    
    MainWidget::MainWidget(QWidget *parent)
        : QWidget(parent)
    {
        m_AuxDialog = new QDialog(this);
        m_AuxDialog->setGeometry(100, 100, 300, 300);
    
        auto hLayout = new QHBoxLayout(this);
        auto btn = new QPushButton("Open Stays On Top Dialog", this);
    
        hLayout->addWidget(btn);
    
        connect(btn, &QPushButton::clicked, this, [this]{
            if (!m_Dialog)
            {
                m_Dialog = new MidLevelDialog(m_AuxDialog);
            }
    
            m_Dialog->show();
        });
    
        setGeometry(400, 100, 300, 300);
    }
    
    MainWidget::~MainWidget()
    {
    }
    
    void MainWidget::setVisible(bool isVisible)
    {
        QWidget::setVisible(isVisible);
        m_AuxDialog->setVisible(isVisible);
    }
    

    Some of the method I have tried but still not ideal:

    1. Create the mid level dialog with Qt::WindowsStaysOnTopHint. But this will cause the highest level modal dialog to go behind it.
    2. Create the mid level dialog with Aux widget as parent. Although this achieve the z-order requirement that I want, in reality its not that easy / correct to create this mid level widget with aux as parent. Another side effect of it that the mid level dialog always will be opened above the Aux widget which I do not want.

    NOTE: This issue does not happen in Mac due to how Mac uses the Qt::Tool flag and modal dialog.

    Please advice. Thanks in advance.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SimonSchroeder
      wrote on last edited by
      #2

      Maybe you can try using floating dock widgets as dialogs.

      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