Displaying help text when the mouse is over pushbutton and lineedit
-
I have a pushbutton and a lineedit , and what i want is , when my mouse is over that pushbutton or lineedit a help text(the purpose of that pushbutton and lineedit) shall be shown besides the pushbutton or lineedit. Please give reply soon , i need it urgently .. Thankx in advance ..
-
What you need is http://qt-project.org/doc/qt-4.8/qtooltip.html
-
Could you please give an example ?
-
Each widget has got a "toolTip":http://qt-project.org/doc/qt-4.8/qwidget.html#toolTip-prop property. Just set it to the requested help text.
-
Could you please give some hints on QWhatsthis ?
If you give some example on this , then i shall be grateful to you ..
Because through tool tip i cant give a long text ..
So i think QWhatsthis is better but i dont know its proper use ..
Thankx in adv . -
If each widget has a toolTip property, which can be used to set a tool tip text, how would you expect setting a whatsThis text will work?
-
This is a better solution than the former (as Lukas says): @myLineEdit->setToolTip("Here is my tooltip");@
-
QWhatsThis is used to specify the help text that pops up when the user uses the '?' button on the title bar(before the min/max/close buttons...it changes the cursor from ' -> ' to ' ->? ') and clicks a widget...what you require is a tool tip(displayed when a user hovers the mouse over the widget)
[quote author="David_Gil" date="1340351885"]This is a better solution than the former (as Lukas says): @myLineEdit->setToolTip("Here is my tooltip");@
[/quote]
this is the way to go -
1---In my tool bar one button is there . When i am clicking that button it calls QWhatsThis::enterWhatsThisMode() .
2-- The cursor changes to some red circle kind of thing .
3--I have used lineedit->setWhatsThis(tr("Hello")) . so when the cursor is moving over that lineedit the cursor again changes (arrow +Question)and after clicking that lineedit one helpbox will pop up and the help box disappears once the user perform some action on that UI or press ESC .Then the cursor changes to simple arrow .NB- lineedit is a object present in that ui file
In between step - 2 to step 3 (mentioned above ) i dont want that red circle cursor . i want my own cursor . but once it passes step 3 the cursor should again changes to simple arrow mark cursor .
Please do reply soon ..
Thankxx in adv .. -
or else how to change that red circle cursor to a transparent one .
[quote author="BibekKumar" date="1340702557"]1---In my tool bar one button is there . When i am clicking that button it calls QWhatsThis::enterWhatsThisMode() . 2-- The cursor changes to some red circle kind of thing . 3--I have used lineedit->setWhatsThis(tr("Hello")) . so when the cursor is moving over that lineedit the cursor again changes (arrow +Question)and after clicking that lineedit one helpbox will pop up and the help box disappears once the user perform some action on that UI or press ESC .Then the cursor changes to simple arrow . NB- lineedit is a object present in that ui file In between step - 2 to step 3 (mentioned above ) i dont want that red circle cursor . i want my own cursor . but once it passes step 3 the cursor should again changes to simple arrow mark cursor . Please do reply soon .. Thankxx in adv ..[/quote] -
when you do not have QWhatsThis set for a widget, the arrow changes to the red crossed out circle to show that the help is not available for that widget...you'll have to give QWhatsThis for all widgets if you want the circle to not appear...it will always appear when it cannot show help for something it is moving over...Alternatively, you could use the setOverrideCursor(Qt::WhatsThisCursor) and when the work is done, restoreOverrideCursor() ...you would need to use some o the QWhatsThis class functions...something like this:
@
myClass::onToolButtonClcked(...) //...this is the SLOT for the helpButton clicked() SIGNAL
{
setOverrideCursor(Qt::WhatsThisCursor);
QWhatsThis::enterWhatsThisMode();
}
//...reimplement event
bool myClass::event(QEvent *event)
{
if(event->type()== QEvent::MouseButtonRelease)
{
QMouseEvent *mouseEvent=static_cast<QMouseEvent *>(event);
if(QWhatsThis::inWhatsThisMode() && mouseEvent->button() == (Qt::LeftButton | Qt::RightButton))
{
restoreOverrideCursor();
return QWidget::event(event);
}
return QWidget::event(event);
}
}
@this might need some refining to work properly...but i would not advise it as you can see this can get very complicated and unnecessary...the red circle is a standard feature which tells us that the action we want to perform is not allowed at the current position...
[EDIT]-code changed a bit(return value in the if block of event())
-
ya this code is little bit complicated ..
can you please give one solution so that the red circle can be a transparent one ? -
it can't be done... the circle is actually another shape of the pointer(like -> or ->?) which is activated automatically by the run time environment...they can be overridden by either the code mentioned earlier or you will have to provide What's This Help for all the other components of your program... that's the only solution...i would recommend that you let the circle be...
or, instead of what's this, you can make the toolButton pop up a QMessageBox with the info you want to give(as you seem to want to give info about only one widget-the lineEdit)...something like this:
@
myClass::onToolButtonClcked(...) //...this is the SLOT for the helpButton clicked() SIGNAL
{
QMessageBox::information(this,tr("--Help Box Title Here--"),tr("--Help Information Here--"),QMessageBox::Close);
//...other code,if any, here
}
@ -
@raghuu - thankx for the reply brother ..
suppose i have 3 files in my project . 2 for the classes lets say class A and class B and 1 for the main() function . i have 2 ui files too , first.ui for class A and second.ui for class B inside which lots of widgets are there and i want to implement what's this option for some widgets , then in this case where can i implement the event() function , which you have mentioned above ..
actually i am new to Qt , thats why not able to get the things quikly ...
-
it would have to be re-implemented for both the classes...also, i don't think it would work exactly as i have written it...it could require changes depending on what your exact code is... so i would say again
[quote author="raaghuu" date="1340706879"]i would not advise it as you can see this can get very complicated and unnecessary...the red circle is a standard feature which tells us that the action we want to perform is not allowed at the current position...[/quote]
-
@raaghuu - ok i am going to implement it in both the classes . then at what time the event() will get called . i mean to say suppose i have 2 lineedit and i push button in the ui and i have implemented "whats this " for 2 lineedit . then in this case how can i call event() .
-
event() is called automatically whenever any event occurs(like a key or mouse-button press,mouse move, etc.)... you don't have to call it... what the code does is that on the toolButton press, it activates the What's This? mode, then, it overrides the cursor so that the red circle is not shown...
the event() function checks to see if an event is a mouse-release event and the What's This? mode is active...if not, it simply passes it on to its parent for normal processing...otherwise, it restores the cursor to its normal form and then passes it on for normal processing...
P.S. - you should change this:[quote author="raaghuu" date="1340706879"]
@
myClass::onToolButtonClcked(...) //...this is the SLOT for the helpButton clicked() SIGNAL
{
setOverrideCursor(Qt::WhatsThisCursor);
QWhatsThis::enterWhatsThisMode();
}
@
[/quote]to this:
@
myClass::onToolButtonClcked(...) //...this is the SLOT for the helpButton clicked() SIGNAL
{
QWhatsThis::enterWhatsThisMode();
setOverrideCursor(Qt::WhatsThisCursor);
}
@