从一行移到另一行时,工具提示未更新 [英] Tooltip is not updated on moving from one row to another

查看:141
本文介绍了从一行移到另一行时,工具提示未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将QAbstractTableModel子类化,并且在data()函数中,我在每行的最后一列中显示图像,并在鼠标悬停时显示工具提示.

I have subclassed QAbstractTableModel and in data() function I am displaying an image in last column of each row and a tooltip on mouse hover.

QVariant MyTableModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid())
    return QVariant();

if (role == Qt::DisplayRole)
{
    switch (index.column())
    {
     // few cases
    default:
        return QVariant();
    }
}
else if (role == Qt::CheckStateRole && index.column() == 0)
{
    int state= tableData.at(index.row()).state;
    if (state)
        return Qt::Checked;
    else
        return Qt::Unchecked;
}
else if (role == Qt::DecorationRole && index.column() == 7 && index.row() > 1)
{
    QPixmap pixMap(fileName);
    return pixMap;
}
else if (role == Qt::ToolTipRole && index.column() == 7 && index.row() > 1)
{
    return QString("Delete");
}
else
    return QVariant();
}

每行上的工具提示文本显示都很好,但是当我将光标从一行的最后一列移动到它下面(或它下面的任何一行)的另一最后一列时,工具提示仍保留在上一行.

Tooltip text is displayed fine on each row but when I move cursor from last column of a row to another last column just below it(or any row below it) tooltip remains on the upper row.

如果在将光标移动到另一行的最后一列之前将光标移动到任何其他单元格,则此问题不会持续. 感谢您的帮助.

This issue does not persist if cursor is moved to any other cell before moving to last column of another row. Thanks for help.

推荐答案

当视图中不同项目的显示为工具提示的数据相同时,则不会调整工具提示的位置.不确定这是设计功能还是bug-需要调查Qt来源.

When data displayed as a tooltip is the same for different items in the view the tooltip position isn't adjusted. Not sure if this is a design feature or bug - would need to look into Qt sources.

尽管如此,您可以很轻松地解决该问题.在Qt文档中,您可以找到以下信息:

You can fix that quite easily though. In Qt documentation you can find such information:

请注意,如果要在项目视图中显示工具提示, 模型/视图架构提供了设置项目工具的功能 小费;例如,QTableWidgetItem :: setToolTip()函数.但是,如果 您想要在项目视图中提供自定义工具提示,则必须 拦截QAbstractItemView :: viewportEvent()中的帮助事件 自己动手处理.

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.

因此,子类化您的视图并覆盖viewportEvent方法应该可以解决您的问题.

Hence, subclassing your view and overriding the viewportEvent method should solve your problem.

这篇关于从一行移到另一行时,工具提示未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆