[Interest] Modeless dialog issue on Mac

Calogero Mauceri mauceri at actgate.com
Tue Nov 14 11:49:53 CET 2023


Hi all,

I have the following problem with dialogs on the Mac.

I have a main window/dialog and I am opening a modeless dialog, I need to
have both the main window/dialog and the modeless dialog visible at the
same time.
I create the modeless dialog as simple as this

QDialog* myDialog = new QDialog(this);
[...]
myDialog->show();
myDialog->raise();
myDialog->activateWindow();

The problem I'm having is that if I click on the main window then the
dialog disappears behind the main application window.
The workaround I've found is to create the dialog as a tool dialog. In that
case the dialog stays always on top of the main application window, but
there are some issues with the modeless dialog default button rendering
when the dialog loses focus as visible in the following image where the
default button in the first one.

[image: tool_dialog.png]

I created a very sample application that opens both a "standard" dialog and
a tool dialog, here are both issues in a screenshot

[image: Screenshot 2023-11-14 alle 11.30.56.png]


The standard dialog is behind the main application, while the tool dialog
default button is not properly rendered when the tool dialog loses focus.

Is there any workaround? Is this a Qt bug?
Attached is the code for the above example.
The example works fine on windows, with both types of dialogs.

-- 
Calogero Mauceri
Software Engineer

Applied Coherent Technology Corporation (ACT)
www.actgate.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20231114/1407eeca/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tool_dialog.png
Type: image/png
Size: 28476 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20231114/1407eeca/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot 2023-11-14 alle 11.30.56.png
Type: image/png
Size: 138940 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20231114/1407eeca/attachment-0003.png>
-------------- next part --------------
#include <QDialog>

class DialogTestApp : public QDialog {
    Q_OBJECT

public:
    DialogTestApp(QWidget* parent = nullptr);

private slots:
    void onOpenDialog();
    void onOpenToolDialog();

private:
    QPushButton* pbOpenDialog;
    QPushButton* pbOpenToolDialog;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dialog_test.pro
Type: application/octet-stream
Size: 200 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20231114/1407eeca/attachment-0001.obj>
-------------- next part --------------
#include "dialog_test.h"

#include <QDialog>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>


DialogTestApp::DialogTestApp(QWidget* parent)
    : QDialog(parent) {

    // buttons
    pbOpenDialog = new QPushButton("Open Dialog", this);
    pbOpenToolDialog = new QPushButton("Open Tool Dialog", this);

    // layout
    QGridLayout* layout = new QGridLayout();
    layout->addItem(new QSpacerItem(100, 10, QSizePolicy::Expanding), 1, 1);
    layout->addWidget(pbOpenDialog, 0, 0);
    layout->addWidget(pbOpenToolDialog, 1, 0);
    layout->addItem(new QSpacerItem(100, 10, QSizePolicy::Minimum, QSizePolicy::Expanding), 2, 0);
    
    // Set the layout for the main widget
    setLayout(layout);

    // Connections
    connect(pbOpenDialog, &QPushButton::clicked, this, &DialogTestApp::onOpenDialog);
    connect(pbOpenToolDialog, &QPushButton::clicked, this, &DialogTestApp::onOpenToolDialog);
}

void DialogTestApp::onOpenDialog()
{
    // default dialog
    QDialog* myDialog = new QDialog(this);
    myDialog->setWindowTitle("Default Dialog");
    myDialog->resize(300, 300);
    QVBoxLayout* newLayout = new QVBoxLayout(myDialog);
    newLayout->addWidget(new QLabel("This is a default dialog"));
    newLayout->addWidget(new QPushButton("Test1"));
    newLayout->addWidget(new QPushButton("Test2"));
    newLayout->addItem(new QSpacerItem(100, 10, QSizePolicy::Minimum, QSizePolicy::Expanding));
    myDialog->show();
    myDialog->raise();
    myDialog->activateWindow();
}

void DialogTestApp::onOpenToolDialog()
{
    /// tool dialog
    QDialog* myDialog = new QDialog(this, Qt::Tool);
    myDialog->setWindowTitle("Tool Dialog");
    myDialog->resize(300, 300);
    QVBoxLayout* newLayout = new QVBoxLayout(myDialog);
    newLayout->addWidget(new QLabel("This is a tool dialog"));
    newLayout->addWidget(new QPushButton("Test1"));
    newLayout->addWidget(new QPushButton("Test2"));
    newLayout->addItem(new QSpacerItem(100, 10, QSizePolicy::Minimum, QSizePolicy::Expanding));
    myDialog->show();
    myDialog->raise();
    myDialog->activateWindow();
}
-------------- next part --------------
#include <QApplication>

#include "dialog_test.h"


int main(int argc, char *argv[]) {
    QApplication app(argc, argv);

    DialogTestApp window;
    window.setWindowTitle("Slider and Label Example");
    window.resize(800, 600);
    window.show();

    return app.exec();
}


More information about the Interest mailing list