Qt window icon window

I use QT.QSystemTrayIconto create a tray icon.

When I click on the tray icon, I need a window that opens right above the icon (in the lower right corner). How can i do this?

+3
source share
4 answers

Do you want to open a window such as QMainWindow or QWidget above the tray icon?

You need to get QDesktopWidgetwith QApplication::desktop(), then request the QDesktopWidget function screenGeometry()to determine the screen size, then create a window and place it correctly in the lower right corner based on the coordinates obtained from screenGeometry().

-1
source
 void main_window::create_tray_icon()
 {
    m_tray_icon = new QSystemTrayIcon(QIcon(":/icon.png"), this);

    QAction *quit_action = new QAction( "Exit", m_tray_icon );
    connect( quit_action, SIGNAL(triggered()), this, SLOT(on_exit()) );

    QAction *another_action = new QAction( "Do something", m_tray_icon );
    connect( another_action, SIGNAL(triggered()), this, SLOT(on_do_something()) );

    QMenu *tray_icon_menu = new QMenu;
    tray_icon_menu->addAction( another_action );
    tray_icon_menu->addAction( quit_action );

    m_tray_icon->setContextMenu( tray_icon_menu );

    m_tray_icon->show();
  }
+2
source

, ( ), manual :

QRect QSystemTrayIcon::geometry()

, 4 , , .

. Win, XP, 7 8, , @MichaelScheper, Mint/GNOME. .

+2

, . , .

, Windows, QSystemTrayIcon:: showMessage. , .

0

Source: https://habr.com/ru/post/1762619/


All Articles