9

I'm writing a C++ Qt desktop appliaction.

Is it possible to show Skype=like notifcations in Qt, without creating a tray icon?

All notification reference I found require a tray icon, which I do not want to create.

The notifications should show when the application is opened and when it is minimized.

Ken Bloom
  • 57,498
  • 14
  • 111
  • 168
sara
  • 3,824
  • 9
  • 43
  • 71

4 Answers4

9

UPDATE: it seems this isn't working with recent versions of Qt. A workaround I found to make this work was to, after creating the QSystemTrayIcon:

  • Call show()
  • Display the desired message with showMessage
  • Call hide()

This works OK for me.


Create a QSystemTrayIcon but never call show() on it. Then you can use QSystemTrayIcon::showMessage to display your popup.

Romário
  • 1,664
  • 1
  • 20
  • 30
Ken Bloom
  • 57,498
  • 14
  • 111
  • 168
  • but then I won't be able to style the notfication, and it will look like system notification, no? – sara Jul 12 '12 at 12:34
  • Tried this on Mac and Windows (Qt 5.3, OS X 10.10 / Win 8.1): the message is only displayed after calling show() so this seems to be no valid answer to the question. – pi3 Nov 11 '14 at 15:06
  • If you never call `show()` on it, this won't work. But you can call `show()`, then `showMessage`, then `hide()` and you will have a similar effect. – Romário Jun 21 '17 at 15:32
3

Just create popup class and show it somwhere on the desktop with always on top flag. Notification may also be a widget

Kamil Klimek
  • 12,884
  • 2
  • 43
  • 58
  • 1
    @sara: Nobody wants to do your work, so please show us some effort. For example, write a [sscce](http://sscce.org) and tell us what gone wrong while you were writing it. [Official documentation](http://doc.qt.nokia.com/) is always a good place to start. – Aleksandr Kravets Jul 12 '12 at 11:48
  • The notification should be a notification like the other notifications, not just a random window. – LtWorf Feb 15 '16 at 18:58
  • 1
    @LtWorf Skype does not use system notifications and it was given as example. In perfect world - sure it would be great to use system notifications, however there are so many differences between platforms that it sometimes makes it impossible to achieve behavaiour you need. – Kamil Klimek Feb 19 '16 at 12:29
2

a little late but you might be interested in this library https://github.com/Snorenotify/Snorenotify/

Snorenotify is a multi platform Qt notification framework. Using a plugin system it is possible to create notifications with many different notification systems on Windows, Unix and Mac.

Doua Beri
  • 10,612
  • 18
  • 89
  • 138
1

Had a similar issue as OP ( But with Python!! ), Romario's answer got me half way to what i wanted.

In my scenario i have a sys-tray tool where i enforce only one being alive via lockfile. However user feedback requested that if they try launching while already open i provide some sort of feedback.

What i found was on Windows - the Romarios answer will lead icons persisting in the systray - if you call setVisible(False) before the show() it will prevent icons appearing/acculumating in the sys-tray :)

My complete sample is

class SimpleNotifier(QtWidgets.QWidget):

    def notify_running(self):
        tray_icon = QtGui.QIcon(Params.TRAY_ICON)
        self.setIcon(tray_icon)
        self.setVisible(False)
        self.show()
        self.showMessage("Hi User", "Application already inside your sys-tray", QtGui.QIcon(Params.TRAY_ICON))

def notify():
    app = QtWidgets.QApplication(sys.argv)
    notify = HUBController.SimpleNotifier()
    notify.notify_running()
    app.exit()

notify()
    

and yes i did sign up for an account after lurking for years just to make this post : :)