0
伙计们我根据QStyledItemDelegate
实现了我的委托类,我遇到的问题是它不显示listView中显示的文本旁边的复选框。我的代表不显示复选框
在我使用我的委托之前,我在listView中显示了这些复选框,所以我知道这个问题存在于这个委托类中。
有什么想法?
EDIT
void Display_Delegate::paint(QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex &index) const
{
QString model_data = index.data().toString();
QFontMetrics metrics = view_->fontMetrics();
int view_width = view_->width();
auto modified_str = adjust_text(metrics,model_data,view_width);//this just makes the string to fit into view, don't bother about it.
QStyleOptionViewItemV4 style_option = option;
initStyleOption(&style_option,index);
QPalette::ColorGroup color_group = style_option.state & QStyle::State_Selected ? QPalette::Active : QPalette::Inactive;
if (style_option.state & QStyle::State_Selected)
{
// painter->setPen(style_option.palette.color(color_group, QPalette::Highlight));
painter->setBackgroundMode(Qt::OpaqueMode);
QColor color(148,231,245,100);
painter->setBackground(QBrush(color));
}
else
{
painter->setPen(style_option.palette.color(color_group, QPalette::Text));
}
painter->drawText(option.rect,modified_str);
}
我正在考虑一个高大的香蕉代基里。你自己呢?哦,也许是一个有编程问题的人发布代码的梦想世界。 – 2012-03-17 14:08:18
@KerrekSB好的,我会在我的委托中发布paint fnc的代码,没问题。你可能会认为模型和代理模型是正确实现的(它们是,它们和dflt委托一起工作) – smallB 2012-03-17 14:27:48
@KerrekSB有趣的是人们如何快速给予+1,即使这个+1是在我实际编辑我的OP之后给出的,你觉得呢? – smallB 2012-03-17 14:55:52