[SOLVED] Implement QBalloonTip
-
Hi,
Has anyone worked with QBalloonTip class? I'm trying not work for me. I tried to import the "qsystemtrayicon.h" class but I can not access the QBalloonTip class. What I'm looking for is to display a message on a button.
Thanks.
-
Hi, can't find a QBalloonTip class in the documentation. Can you please provide a link to that class in the documentation?
-
Hi @Wieland,
The reference can be found at the following link. That's all I could find.
http://cep.xray.aps.anl.gov/software/qt4-x11-4.2.2-browser/d7/d10/class_q_balloon_tip.html
What I'm trying to find something like this.
http://stackoverflow.com/questions/23523211/qt-tooltip-with-arrow
Thanks.
-
Ah! Found it in the Qt4.5.3 sources: http://qt4-x11.sourcearchive.com/documentation/4.5.3really4.5.2/src_2gui_2util_2qsystemtrayicon__p_8h_source.html . QBalloonTip isn't part of the public API but defined in the (private) internals of of QSystemTrayIcon:
qsystemtrayicon_p.h
. You said that you includedqsystemtrayicon.h
, but you need to include qsystemtrayicon_p.h to use QBalloonTip. Of course you're free to do so, but I can only discourage you from doing this. -
Hi @Wieland,
Thank you very much for the information. If it is a private source, you can not be used in a free app?
Thanks,
-
You can use it! Not being part of the public API means that QBalloonTip could be changed or removed from the next Qt version without any warning. You can not rely on it.
-
Hi @Wieland,
Thank you very much.
-
Hello again @Wieland
One question. You know how you could implement this type of popup in QT?
https://www.dropbox.com/s/as4wc47dd78vxxk/cqj30.jpg?dl=0
Thanks,
-
@kapsule Hi! The link is dead!
-
@Wieland Hi,
Sorry, https://www.dropbox.com/s/zg7xm0hl5zjm8uv/cqj30.jpg?dl=0
-
@kapsule The following should work: First create a new class (say: MyBallonTip) that inhertits QWidget. Override its
void QWidget::paintEvent(QPaintEvent *event)
so that it draws the desired geometry. Then set its flags toQt::Window | Qt::WA_TranslucentBackground |Qt::FramelessWindowHint
.
I have no time to test it right now. Please tell me if it works. See you later! -
@kapsule Hi again! I just tested what I suggested to you and this works:
myballoontip.h
#ifndef MYBALLOONTIP_H #define MYBALLOONTIP_H #include <QWidget> class MyBalloonTip : public QWidget { Q_OBJECT public: explicit MyBalloonTip(QWidget *parent = 0); ~MyBalloonTip(); protected: void paintEvent(QPaintEvent*); }; #endif // MYBALLOONTIP_H
myballontip.cpp
#include "myballoontip.h" #include <QPaintEvent> #include <QPainter> #include <QPen> #include <QBrush> MyBalloonTip::MyBalloonTip(QWidget *parent) : QWidget(parent) { this->setAttribute(Qt::WA_TranslucentBackground); this->setWindowFlags(Qt::Window |Qt::FramelessWindowHint); this->resize(200,100); } MyBalloonTip::~MyBalloonTip() { } void MyBalloonTip::paintEvent(QPaintEvent*) { QPainter painter(this); QPen pen( QColor("orange") ); pen.setWidth(5); painter.setPen(pen); QBrush brush(QColor("lightblue")); painter.setBrush(brush); painter.drawRect(0,0,this->width(), this->height()-50); painter.drawRect(0,0,60,this->height()); pen.setColor(QColor("black")); painter.setPen(pen); painter.drawText(20,30, "This is a tooltip!"); }
This is what the result looks like: https://drive.google.com/file/d/0B2D1UtsPfTx-YnhsVFE1QThuT0E/view?usp=sharing
Hope this can serve you as a starting point!
Cheers! -
Hi @Wieland
Perfect, thank you very much. Great job :)