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. Weird behavior of QT windows on Linux
Forum Updated to NodeBB v4.3 + New Features

Weird behavior of QT windows on Linux

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 53 Views 1 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.
  • deisikD Offline
    deisikD Offline
    deisik
    wrote last edited by deisik
    #1

    I have a main window (QMainWindow) which has a child widget (QDialog) and a window (another QDialog) on top of them (without a parent). When I hit the Minimize button on the first widget, the widget is minimized together with the main window (like it was modal). If I then close the second widget, the main window is restored

    This happens only when the second widget is visible and only on Linux. I tested it with two window managers (IceWM and openbox) -- the behavior is the same. On Windows only the widget is minimized (as should be)

    So the issue seems to be X related

    C 1 Reply Last reply
    0
    • deisikD Offline
      deisikD Offline
      deisik
      wrote last edited by deisik
      #2

      In the sample code below the widgets are shown by first double-clicking on the main window and then double-clicking on the dialog itself

      main.cpp

      #include "main_window.h"
      #include <QApplication>
      
      int main(int argc, char *argv[]) {
          QApplication app(argc, argv);
          MainWindow window;
      
          window.show();
      
          return app.exec();
      }
      

      main_window.h

      #ifndef MAINWINDOW_H
      #define MAINWINDOW_H
      
      #include <QMainWindow>
      
      #include "dialog.h"
      
      class MainWindow : public QMainWindow {
          Q_OBJECT
      public:
          WindowDialog *first;
      
          MainWindow(QWidget *parent = nullptr);
      
      protected slots:
          void mouseDoubleClickEvent(QMouseEvent*);
      };
      
      #endif // MAINWINDOW_H
      

      main_window.cpp

      #include "main_window.h"
      
      void MainWindow::mouseDoubleClickEvent(QMouseEvent *event) {
          if (first == 0) {
              first = new WindowDialog(this);
      
              first->setMinimumSize(300, 200);
              first->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);
              first->setWindowTitle("First dialog");
      
              first->show();
          }
          else {
              if (first->isHidden() || first->isMinimized()) {
                  first->setWindowState(Qt::WindowState::WindowActive);
                  first->show();
                  first->activateWindow();
              }
          }
      }
      
      MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
          first = 0;
      
          showMaximized();
      }
      

      dialog.h

      #ifndef DIALOG_H
      #define DIALOG_H
      
      #include <QDialog>
      
      class WindowDialog : public QDialog {
          Q_OBJECT
      public:
          WindowDialog *final;
      
          explicit WindowDialog(QWidget *parent = nullptr);
      signals:
      protected slots:
          void mouseDoubleClickEvent(QMouseEvent*);
      };
      
      #endif // DIALOG_H
      

      dialog.cpp

      #include "dialog.h"
      
      void WindowDialog::mouseDoubleClickEvent(QMouseEvent *event) {
          if (final == 0) {
              final = new WindowDialog(); // no parent
      
              final->setMaximumSize(200, 100);
              final->setWindowFlags(Qt::Dialog | Qt::WindowStaysOnTopHint | Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);
              final->setWindowTitle("Next dialog");
      
              final->show();
          }
          else {
              if (final->isHidden() || final->isMinimized()) {
                  final->setWindowState(Qt::WindowState::WindowActive);
                  final->show();
                  final->activateWindow();
              }
          }
      }
      
      WindowDialog::WindowDialog(QWidget *parent) : QDialog{parent} {
          final = 0;
      }
      
      1 Reply Last reply
      0
      • deisikD Offline
        deisikD Offline
        deisik
        wrote last edited by deisik
        #3

        So how can I correct this behavior?

        Put simply, the first widget (a child of MainWindow) shouldn't be on top of other windows (other than the main window) and the main window shouldn't get minimized along with it. It's okay if the child is minimized with the parent, but not the other way around

        Pl45m4P 1 Reply Last reply
        0
        • deisikD deisik

          So how can I correct this behavior?

          Put simply, the first widget (a child of MainWindow) shouldn't be on top of other windows (other than the main window) and the main window shouldn't get minimized along with it. It's okay if the child is minimized with the parent, but not the other way around

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote last edited by
          #4

          @deisik

          Can you reproduce the weird/incorrect behavior also when not messing around with WindowStates and WindowFlags?!
          Maybe it's related to that


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          0
          • deisikD deisik

            I have a main window (QMainWindow) which has a child widget (QDialog) and a window (another QDialog) on top of them (without a parent). When I hit the Minimize button on the first widget, the widget is minimized together with the main window (like it was modal). If I then close the second widget, the main window is restored

            This happens only when the second widget is visible and only on Linux. I tested it with two window managers (IceWM and openbox) -- the behavior is the same. On Windows only the widget is minimized (as should be)

            So the issue seems to be X related

            C Offline
            C Offline
            ChrisW67
            wrote last edited by
            #5

            @deisik said in Weird behavior of QT windows on Linux:

            So the issue seems to be X related

            Your somewhat unorthodox code works just fine here on Kubuntu 22.04, Qt 6.8, and

            vendor string:    The X.Org Foundation
            vendor release number:    12101011
            X.Org version: 21.1.11
            

            So this is either a windows manager difference or that you are not actually using X11 but Wayland.

            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