Unsolved Is it possible to use tooltip with scrollbar in qt?
-
Actually the contents written inside line edit is too long the tooltip fails to show whole data i want the scrollbar do the work so that the complete text can be read
-
@Himanshu-charde I don't think this is a good idea. Tooltips are meant to be used for short texts, not something user has to scroll.
-
If that's really what you want, then you should overwrite your widget's "event"-function, filter for the ToolTip-event and display a QLineEdit with the text at the mouse pointer position.
Something like this:bool MyWidget::event(QEvent* p_event) { if (QEvent::ToolTip == p_event->type()) { QHelpEvent* p_help_event = static_cast<QHelpEvent*>(p_event); // Create a QLineEdit with your text and position it at p_help_event.globalPos() return true; } return QWidget::event(p_event); }
Of course you need to make sure that the QLineEdit disappears once it loses focus, like when the user clicks anywhere else but the QLineEdit (there are also events for this). Hope that helps.
-
@Himanshu-charde
Both @jsulm's & @qwasder85's answers are good, in their respective ways.Another possibility for you to consider: https://doc.qt.io/qt-5/qwhatsthis.html
"What's This?" help texts are typically longer and more detailed than tooltips,
You could have a look to see if you could leverage this for your "long tooltips"?
-
@JonB
actually i am trying to set whatsthis to the TableWidget_item but it is not working for me
QAction *newAct = new QAction(tr("&New"),ui->TW_Contents);
newAct->setShortcut(tr("Ctrl+N"));
newAct->setStatusTip(tr("Create a new file"));
newAct->setWhatsThis(strToolTipText); -
@qwasder85 said in Is it possible to use tooltip with scrollbar in qt?:
bool MyWidget::event(QEvent* p_event)
{
if (QEvent::ToolTip == p_event->type())
{
QHelpEvent* p_help_event = static_cast<QHelpEvent*>(p_event);
// Create a QLineEdit with your text and position it at p_help_event.globalPos()
QLineEdit *lineEtool=new QLineEdit(this);
ui->lineEtool->setText(strToolTipText);
//here i am stucked how to position it
return true;
}
return QWidget::event(p_event);
} -
Hi,
have you tried this? In fact you are using a
QTableWidget
(Model / View), this could solve your problem.Note that, if you want to show tooltips in an item view, the model/view architecture provides functionality to set an item's tool tip; e.g., the QTableWidgetItem::setToolTip() function. However, if you want to provide custom tool tips in an item view, you must intercept the help event in the QAbstractItemView::viewportEvent() function and handle it yourself.
(from https://doc.qt.io/qt-5/qtooltip.html#details) -
@Pl45m4 I am not able to show large amount of text on the tooltip i am trying to find different alternative so that the complete text can be read
-
@Himanshu-charde Have you tried
lineEtool->move(p_help_event->globalPos();
You may even want to consider showing the QLineEdit in a QDialog, for more control.
-
thank you
@jsulm @qwasder85 @JonB @Pl45m4 for your responses -
@Himanshu-charde Hi!
I meet the same problem recently, could you please tell me if you solve it and how?
Thank you very much! -
Hi
I think he intercepted the tooltip event and showed
a QLineEdit instead. (see code higher up )However, it's not clear how he made it disappear again like
the tooltip does.