【问题标题】:How can I access to different column in displayText function in QStyledItemDelegate如何访问 QStyledItemDelegate 中 displayText 函数中的不同列
【发布时间】:2021-02-08 07:07:58
【问题描述】:

我将更改我的QTableView 列之一的显示文本。我继承自QStyledItemDelegate类,并根据以下内容更改displayText的定义:

QString CellIdDelegate::displayText(const QVariant &value, const QLocale &locale) const
{
    QString currentColumn = value.toString();
    QString anotherColumn = ....;

    return currentColumn + anotherColumn;
}

然后使用setItemDelegateForColumn

如何访问我的QTableView 中另一列的值。

【问题讨论】:

    标签: c++ qt delegates


    【解决方案1】:

    你不能因为 displayText() 只针对一个单元格。它只是为了添加例如前缀或后缀。如果要显示其他文本,请相应修改 Qt::DisplayRole 返回的数据。这对代表来说不算什么。

    【讨论】:

    • 谢谢,你能解释一下你的解决方案吗?
    • 不知道还要解释什么。看看 QAbstractTableModel::data() 及其示例。
    猜你喜欢
    • 1970-01-01
    • 2017-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多