1

This is a request to see if anyone has found any work-arounds or hacks to prevent the somewhat random placement of X11 Qt windows. These X11 pecularities are discussed at the bottom of this page in the Qt documentation. This occurs often in my software, where I need to display a window, then popup and error message, which always appears way off on in different screen (top left). This locks up the main application (modality) and drags down my user's experience and trust in my software.

I'm running RHEL 7.2 KDE (X11 based system). My searches for solutions and attempts have been fruitless the past few days.

My semi solution ideas: I'm considering implementing a status bar at the bottom that displays errors.. but I feel that's too easy to ignore and doesn't have the alarming affect as a popup. For sub windows from my main application, I set the popup's parent to the main window and so that it at least the popup appears on top of the main window and not up on a random monitor.

Minimum reproducible example in a Qt 5.13 environment:

    void MainWindow::on_actionShowEditorWindow_pressed() // called from a menu on a QMainWindow
    {
         editorWindow.show(); //editor Window is a QMainWindow
         editorWindow.activateWindow(); // to request focus
         // according to Qt documentation X11 systems asynchronously calculate the screen position after .show()
         // so when the message below is displayed, the window manager doesn't know where the editor window is, so it defaults to the top left screen
         QMessageBox::warning(editorWindow, tr("title"), "This message always appears on the top left screen");
    }

Here's my editorWindow constructor:

EditorWindow::EditorWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::EditorWindow)
{
     ui->setupUi(this);
}

My window manager is kwin, running KDE on RHEL 7.2. Most of my users run a 4 monitor setup and the environments are RHEL 7.2 with a mix of gnome and KDE.

Thanks to anyone who can help.

Edit: I'm currently looking into configuring kwin, my windows manager, for a fix.

Garret
  • 1,137
  • 9
  • 17
  • 1
    Can you edit your question to include a [mcve] that demonstrates the problem (albeit only on selected platforms). While a lot/most of the behaviour of top level windows on X11 is down to the window manager I've never had issues with things such as popup messages. You might also give some info regarding the window manager you're using (`kwin`?). – G.M. Feb 19 '20 at 18:54
  • 1
    I can't reproduce the issue using the code shown. With any window manager I try (including KWin on KDE) the message box always pops up centred on the parent. – G.M. Feb 20 '20 at 11:36
  • Thanks for trying. This makes me think the issue might be with my window manager and not my code. If I figure anything out, I'll post it here. – Garret Feb 20 '20 at 15:13
  • 1
    For what it's worth, the behaviour you're seeing is what I might expect if a null parent was specified. So something like `QMessageBox::warning(nullptr, tr("title"), "This...` -- where there's no parent-child relationship between the message dialog and any of the apps top-level windows. – G.M. Feb 20 '20 at 15:21
  • Interesting. I've tried this: QMessageBox::warning(this, tr("title"), "This.... and the popup appears over the MainWindow as expected. This is better than appearing on another screen but not perfect. The issue could be how I'm constructing the editorWindow object. I'm going to add that code to the question. – Garret Feb 20 '20 at 15:39
  • 1
    Okay, so if `editorWindow` is null when passed to `QMessageBox::warning(...)` that would go some way to explaining the issue. Maybe. – G.M. Feb 20 '20 at 15:42
  • I just tried passing nullptr to `QMessageBox` and strangely enough it appeared the same as if I passed `this`. I doubt editorWindow is null because it appears and is a fully functioning window. – Garret Feb 20 '20 at 15:55

0 Answers0