Qabstractview (Qtreeview, Qtableview, etc.) mouse over display tooltip (help) currently points to cell text __qt5

Source: Internet
Author: User

The title, the effect for Qtreeview or Qtableview in the case of focus, move the mouse and a short stay, you can eject the ToolTip and display the current mouse pointer to the row of data

There are two different ways to display data that is too long to be hidden:


1, the use of the entire window/view event filter

Suppose the window has a TreeView control with the name

BOOL Mywidget::eventfilter (QObject *editor, qevent *event)
{
	if (Event->type () ==qevent::tooltip) {
        Qhelpevent *helpevent = static_cast<qhelpevent *> (event);	Tooptip Pop-up event to help
        qpoint P_top=helpevent->globalpos ();	Tooptip display position, global coordinates
		qpoint p_view=ui->treeview->mapfromglobal (p_top);	Converts the global coordinates of the mouse to the coordinates in the TreeView
        qmodelindex Currentindex=ui->treeview->indexat (TMPP);	Gets the index
        QString name=currentindex.data (Qt::D isplayrole) to which the mouse points. toString ();
        Qtooltip::showtext (p_top, name);	Show ToolTip return
        true;
    }
    Return Qwidget::eventfilter (editor, event);
}

2, custom model, inherit from Qstandarditemmodel

Under the model class's data function, add the following:

if (role = = Qt::tooltiprole) {
	QString name=index.data (Qt::D isplayrole). toString ();
    Return Qtooltip.showtext (Qcursor.pos (), name);


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.