PDA

View Full Version : problem in QTooltip



wagmare
3rd April 2009, 13:32
hi friends,
i am having a window with size (10,800,1010,40) .. its having a button (diagnosButton) ... a thread is running parallel which will receive communication from server and emit a signal newMessage (QString) ... in my mainwindow i get the signal of thread and called a slot ()
this is the slot


void TidBar::showToolTip(const QString &message)
{
QFont serifFont("Times", 12, QFont::Bold);
QPalette color;
int setval = 0;
color.setColor( QPalette::Inactive,QPalette::QPalette::ToolTipBase ,Qt::yellow);
//value = diagnosButton->mapToGlobal(diagnosButton->rect().topLeft());
value = diagnosButton->mapToGlobal(QPoint(0, 0));
qreal x = value.x();
qreal y = value.y();
QRect rectval = this->rect();
QPoint value2 (x + 70, y - 54);

QToolTip::setPalette(color);
QToolTip::setFont(serifFont);
QToolTip::showText(value2, message,this ,rectval );

}

i try to show a tooltip with the message from the thread signal newMessage(QString) .... i thought this tooltip will last for long until i move the cursor outside the window ...
but the tooltip disapper or hide afer few seconds .... i dont know where i mistaked .... please help

aamer4yu
3rd April 2009, 13:40
QToolTip has a default timeout of 10 seconds.
There are 2 ways you can display it longer -
1) Easy way : Use ur timer of say 5 sec, and show tooltip every 5 sec.. u can code logic when to quit

2) harder way : make your custom widget, override the tooltip event, and display your custom tooltip. You can close it on lost focus.

second way might be better..

talk2amulya
3rd April 2009, 14:08
umm..i'll say that instead of creating a custom widget and handling its tooltip event, you could go ahead and make a custom TOOLTIP itself..its just like creating a custom widget, just set the window flag to be Qt::tooltip..here is how u should go about it:

1. have the constructor take the heading and tooltip strings..put those in layouts..also include a close button so that it depends on user when to close the tooltip..or you could also have a timer started in there itself..as ur requirement may be

2. have a function in it like showTooltip(QWidget *parent,...), here parent would be the widget u need to show the tooltip on..u can use the code u wrote earlier to find the position where to show the tooltip on.

3. u can also add functions to show the tooltip on right/left of parent, thus giving you good control over everything.

And when u think about it, its very easy to make, about 2-3 hours work..other details are easy to figure out

wagmare
6th April 2009, 06:47
thanks to both mr.Aamer and madam.Amulya... sorry for the late reply .... i will follow your suggestion and soon reply ... thanks

aamer4yu
6th April 2009, 11:15
Sorry to interrupt,
but I guess its Mr. Amulya, or Madam :confused::confused:

talk2amulya
6th April 2009, 12:06
whoa :D , how did you i got a sex change operation? :D

wagmare
6th April 2009, 12:41
my mistake ... from your name i thought u are an intelligent lady .... are u male or female ...?

talk2amulya
6th April 2009, 12:59
why do you still have doubts that i m a hunky-dunky male :cool:

aamer4yu
6th April 2009, 14:09
:confused::confused: Now am confused... cant u reply in a clear way :cool: