tags:

views:

54

answers:

3

Hi,

I am using QT.QSystemTrayIcon to create a tray icon.

When clicking on a tray icon, I need a window to opens right above the icon (in the bottom right corner). How can I do this?

Brgds,

kNish

+2  A: 
 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();
  }
Exa
A: 

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

You need to get a QDesktopWidget using QApplication::desktop(), then query that QDesktopWidget's screenGeometry() function to determine the screen dimension, then create a window and position it appropriately in the right bottom corner based on the coordinates obtained from screenGeometry().

teukkam
A: 

I'm not sure what exactly you mean by a window. My first answer refers to a context menu that popups where you can add several actions.

If you want to have a small information window with a message in it like in Windows, you should use QSystemTrayIcon::showMessage. There you can popup a message, set the duration of this message and set an icon for it.

Exa