0

I'm trying to implement some kind of volume slider in Qt. I have added the QWidget with a QSlider on it. It works fine for me... But! QWidget shows on the screen center. But I need it on top of the tray icon.

Does anybody knows how to do that?

Code:

VolumeSlider::VolumSlider(QWidget *parent) : QWidget(parent)
{
    setWindowFlags(Qt::Popup);
    resize(20, 150);

    slider = new QSlider(Qt::Vertical, this);
    slider->setRange(0, 100);
    slider->setSingleStep(5);
    slider->setPageStep(10);
    slider->setValue(currentVolume);
    slider->resize(20, 150);
}

I'm showing the QWidget witha QSlider on middle click:

connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
  this, SLOT(trayIconClicked(QSystemTrayIcon::ActivationReason)));

And a slot implementation is:

void VolumeSlider::trayIconClicked(QSystemTrayIcon::ActivationReason reason)
{
    if (reason == QSystemTrayIcon::MiddleClick) {
        show();
    }
}

Thank you for your attention!

Best regards!

ddmytrenko
  • 796
  • 7
  • 16
  • You can `move()` widget to `Cursor::pos()` position before showing. (Position should be adjusted on size of widget). If you need more general solution - create menu for your tray icon and fill it with `QWidgetAction` item. – Dmitry Sazonov Oct 09 '13 at 06:08
  • Actually I'm already have the menu. It appears on mouse right click. But now I need to add the slider popup for mouse middle click. And thanks for the `move` to `Cursor::pos()` advice. – ddmytrenko Oct 09 '13 at 14:34
  • @ddmytrenko Hi, i'm having the same problem (i'm using PyQt5), did you find a solution to your problem? Thanks in advance! – sunyata Jul 31 '18 at 15:26

1 Answers1

1

You may consider the QSystemTrayIcon Class:

http://doc.qt.io/qt-5/qsystemtrayicon.html

And this example:

http://doc.qt.io/qt-4.8/qt-desktop-systray-example.html

jesterjunk
  • 2,342
  • 22
  • 18
Tito Tito
  • 248
  • 3
  • 10