如何评估江西中联建设集团网站的权重?
摘要:江西中联建设集团有限公司网站,什么网站权重大,广告推广营销网站,网站开发德菁如何让qt tableView每个item中个别字用不同颜色显示? 从上面图片可以看到,Item为红色&
江西中联建设集团有限公司网站,什么网站权重大,广告推广营销网站,网站开发德菁如何让qt tableView每个item中个别字用不同颜色显示#xff1f; 从上面图片可以看到#xff0c;Item为红色#xff0c;数字5为黑色。
要实现在一个控件实现不同颜色#xff0c;目前想到的只有QTextEdit 、QLabel。有两种方法#xff0c;第一种是代理#xff0c;第二种是…如何让qt tableView每个item中个别字用不同颜色显示 从上面图片可以看到Item为红色数字5为黑色。
要实现在一个控件实现不同颜色目前想到的只有QTextEdit 、QLabel。有两种方法第一种是代理第二种是通过setIndexWidget函数实现。 QString abc(span style\color: red;\);abc.append(Item);abc.append(/span);abc.append(5);QTextEdit *text new QTextEdit();text-setText(abc);QTextEdit 可以实现多种样式字体字号加粗倾斜下划线都可以实现。
第一种方法
写一个自定义代理类继承QStyledItemDelegate类重写paintsizeHint方法。运用QAbstractItemView的三个方法设置代理。
QAbstractItemView::setItemDelegate
QAbstractItemView::setItemDelegateForColumn
QAbstractItemView::setItemDelegateForRow例子
class MyDelegatel : public QStyledItemDelegate
{Q_OBJECT
public:explicit MyDelegatel(QObject *parent nullptr);//自定义代理必须重新实现以下4个函数//创建编辑组件QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem option,const QModelIndex index)const override;//从数据模型获取数据显示到代理组件中void setEditorData(QWidget *editor, const QModelIndex index)const override;//将代理组件的数据保存到数据模型中void setModelData(QWidget *editor, QAbstractItemModel *model,const QModelIndex index)const override;//更新代理编辑组件的大小void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem option,const QModelIndex index)const override;// QAbstractItemDelegate interface
public:void paint(QPainter *painter, const QStyleOptionViewItem option, const QModelIndex index) const override;QSize sizeHint(const QStyleOptionViewItem option, const QModelIndex index) const override;
};paint方法 This pure abstract function must be reimplemented if you want to provide custom rendering. Use the painter and style option to render the item specified by the item index. 如果要提供自定义呈现则必须重新实现此纯抽象函数。使用painter和style选项可以渲染由项目索引指定的项目。 If you reimplement this you must also reimplement sizeHint(). 如果重新实现此操作则还必须重新实现sizeHint。
