Question

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!

No correct solution

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top