Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-118656

QSystemTrayIcon::geometry returns wrong value

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: P2: Important P2: Important
    • None
    • 5.15.15, 6.5.3, 6.6.0
    • None

      The sample I am testing with:

      #include <QApplication>
      #include <QMainWindow>
      #include <QSystemTrayIcon>
      #include <QMenu>
      #include <QAction>
      #include <QDebug>
      
      class SystemTrayExample : public QMainWindow
      {
          Q_OBJECT
      
      public:
          SystemTrayExample(QWidget *parent = nullptr)
              : QMainWindow(parent)
          {
              initUI();
          }
      
      private:
          void initUI()
          {
              QMenu *trayIconMenu = new QMenu(this);
      
              QAction *exitAction = new QAction("Exit", this);
              connect(exitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
              trayIconMenu->addAction(exitAction);
      
              QSystemTrayIcon *trayIcon = new QSystemTrayIcon(this);
              trayIcon->setIcon(QIcon("./icon.png")); // Set the icon (replace with your icon path)
              trayIcon->setContextMenu(trayIconMenu);
              trayIcon->show();
      
              qDebug() << "Showing system tray icon at" << trayIcon->geometry();
          }
      };
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          SystemTrayExample window;
          window.show();
      
          return app.exec();
      }
      #include "main.moc"
      

      Although the icon can be displayed correctly in system tray and also functions as expected, geometry() almost always returns QRect(0,0 0x0) which does not make any sense at all.

      Very seldomly by 5.15 (I don't see the pattern, but it happens sometimes) geometry() returns something like QRect(17,1231 40x40). It is not all 0 but does not make sense either. System tray is at lower right corner so definitely shouldn't be (17, 1231). Not sure if the size of 40*40 is correct or not. Qt::AA_EnableHighDpiScaling does not make any difference.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            luqiaochen Luqiao Chen
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes