Balloon-tips with Qt

佐手、 提交于 2019-12-08 17:43:56

问题


In my Qt application, I'd like to use balloons/balloon-tips as shown in the Windows user experience guide (not the system tray balloons).

Is this supported by Qt? I haven't found anything. Is there an Open Source library out there for this (Qxt does not have it)? What's the best way to create that myself?


回答1:


You can use QBalloonTip which is an internal class defined in :

  • Qt 5:

    QtDir/Src/qtbase/src/widgets/util/qsystemtrayicon_p.h

  • Qt 4:

    QtDir/src/gui/utils/util/qsystemtrayicon_p.h

QBalloonTip inherits QWidget and it is implemented in qsystemtrayicon.cpp at the same directory. It has the following method to show a balloon tip:

void QBalloonTip::balloon(const QPoint& pos, int msecs, bool showArrow)

You can modify the source code of this class to have your desired balloon tip.




回答2:


To use private class QBaloonTip in Qt 5.12 you need to do the following:

1) add QT += widgets-private to your PRO file to be able to include private headers

2) #include <QtWidgets/private/qsystemtrayicon_p.h> in your source file

Then call static method showBallon() or instantiate it and call baloon(). But it is really only for system tray and it is a private API, which can change any time. I personally would not use it. But if you want to know how it is rendered, have a look at https://code.woboq.org/qt5/qtbase/src/widgets/util/qsystemtrayicon.cpp.html#_ZN11QBalloonTip10paintEventEP11QPaintEvent




回答3:


Search for QBalloonTip class (in Qt documentation (doxygen reference) and code base, look how it is implemented, and use similar technique.



来源:https://stackoverflow.com/questions/7879205/balloon-tips-with-qt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!