当前位置: 首页 > news >正文

手机微网站 模板机械企业网站模板 蓝色大气 dede织梦企业模板

手机微网站 模板,机械企业网站模板 蓝色大气 dede织梦企业模板,网站怎样制作流程,如何选择专业网站开发商如何让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。 例子 void StarDelegate::paint(QPainter *painter, const QStyleOptionViewItem option,const QModelIndex index) const {if (index.data().canConvertStarRating()) {StarRating starRating qvariant_castStarRating(index.data());if (option.state QStyle::State_Selected)painter-fillRect(option.rect, option.palette.highlight());starRating.paint(painter, option.rect, option.palette,StarRating::EditMode::ReadOnly);} else {QStyledItemDelegate::paint(painter, option, index);} }例子来自官方qt6\Examples\Qt-6.5.2\widgets\itemviews\stardelegate\stardelegate.cpp。 sizeHint方法 This pure abstract function must be reimplemented if you want to provide custom rendering. The options are specified by option and the model item by index. 如果要提供自定义呈现则必须重新实现此纯抽象函数。选项由选项指定模型项由索引指定。 If you reimplement this you must also reimplement paint(). 如果你重新实现这个你也必须重新实现paint。 例子 QSize StarDelegate::sizeHint(const QStyleOptionViewItem option,const QModelIndex index) const {if (index.data().canConvertStarRating()) {StarRating starRating qvariant_castStarRating(index.data());return starRating.sizeHint();}return QStyledItemDelegate::sizeHint(option, index); }第二种方法 通过setIndexWidget函数实现 如果是QtableWidget非常简单写好一个widget调用setCellWidget方法设置就可以了。 // 创建按钮 ui-tableWidget-setCellWidget(rowIndex,6,Widget_btn);//表格中添加Widget看到QtableWidget有一个setCellWidget方法我在想tableView是否有也类似的方法。好在tableView也提供了类似的方法方法隐在父类QAbstractItemView里。 void QAbstractItemView::setIndexWidget(const QModelIndex index, QWidget *widget)Sets the given widget on the item at the given index, passing the ownership of the widget to the viewport. 在给定索引的项目上设置给定的小部件将小部件的所有权传递给视口。 If index is invalid (e.g., if you pass the root index), this function will do nothing. 如果索引无效例如如果传递根索引此函数将不起任何作用。 The given widget’s autoFillBackground property must be set to true, otherwise the widget’s background will be transparent, showing both the model data and the item at the given index. 给定小部件的autoFillBackground属性必须设置为true否则小部件的背景将是透明的显示给定索引处的模型数据和项。 If index widget A is replaced with index widget B, index widget A will be deleted. For example, in the code snippet below, the QLineEdit object will be deleted. 如果用索引小部件B替换索引小部件A则索引小部件将被删除。例如在下面的代码片段中QLineEdit对象将被删除。 setIndexWidget(index, new QLineEdit);...setIndexWidget(index, new QTextEdit); This function should only be used to display static content within the visible area corresponding to an item of data. If you want to display custom dynamic content or implement a custom editor widget, subclass QStyledItemDelegate instead. 此功能应仅用于在与数据项相对应的可见区域内显示静态内容。 See also indexWidget() and Delegate Classes. 如果要显示自定义动态内容或实现自定义编辑器小部件请改为使用子类QStyledItemDelegate。 例子 Widget::Widget(QWidget *parent): QWidget(parent) , ui(new Ui::Widget) {ui-setupUi(this);QTableView *tableView ui-tableView;QStandardItemModel *model new QStandardItemModel();tableView-setModel(model);// Create and populate QStandardItem objectsQStandardItem *item1 new QStandardItem(Item 1);QStandardItem *item2 new QStandardItem(Item 2);// Add child items to item1item1-appendRow(new QStandardItem(Child 1));item1-appendRow(new QStandardItem(Child 2));QStandardItem *item3 new QStandardItem();QString abc(span style\color: red;\);abc.append(Item);abc.append(/span);abc.append(5);QTextEdit *text new QTextEdit();text-setText(abc);text-setFrameShape(QFrame::NoFrame);text-setFocusPolicy(Qt::ClickFocus);text-setReadOnly(true);text-setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);// 设置水平滚动条按需显示text-setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);// 设置垂直滚动条不显示// Add items to the modelmodel-appendRow(item1);model-appendRow(item2);model-appendRow(item3);tableView-setIndexWidget(model-index(model-rowCount()-1,0),text); }
文章转载自:
http://www.morning.ktblf.cn.gov.cn.ktblf.cn
http://www.morning.srkwf.cn.gov.cn.srkwf.cn
http://www.morning.zxqyd.cn.gov.cn.zxqyd.cn
http://www.morning.xsrnr.cn.gov.cn.xsrnr.cn
http://www.morning.gqnll.cn.gov.cn.gqnll.cn
http://www.morning.yptwn.cn.gov.cn.yptwn.cn
http://www.morning.pljdy.cn.gov.cn.pljdy.cn
http://www.morning.dpfr.cn.gov.cn.dpfr.cn
http://www.morning.kqpxb.cn.gov.cn.kqpxb.cn
http://www.morning.gyylt.cn.gov.cn.gyylt.cn
http://www.morning.syfty.cn.gov.cn.syfty.cn
http://www.morning.jbblf.cn.gov.cn.jbblf.cn
http://www.morning.dqbpf.cn.gov.cn.dqbpf.cn
http://www.morning.zfrs.cn.gov.cn.zfrs.cn
http://www.morning.xkbdx.cn.gov.cn.xkbdx.cn
http://www.morning.nrbqf.cn.gov.cn.nrbqf.cn
http://www.morning.dndk.cn.gov.cn.dndk.cn
http://www.morning.rhpy.cn.gov.cn.rhpy.cn
http://www.morning.qbpqw.cn.gov.cn.qbpqw.cn
http://www.morning.kxyqy.cn.gov.cn.kxyqy.cn
http://www.morning.kpcxj.cn.gov.cn.kpcxj.cn
http://www.morning.dnmwl.cn.gov.cn.dnmwl.cn
http://www.morning.hwpcm.cn.gov.cn.hwpcm.cn
http://www.morning.bynf.cn.gov.cn.bynf.cn
http://www.morning.gwtgt.cn.gov.cn.gwtgt.cn
http://www.morning.thrtt.cn.gov.cn.thrtt.cn
http://www.morning.rbsmm.cn.gov.cn.rbsmm.cn
http://www.morning.niukaji.com.gov.cn.niukaji.com
http://www.morning.fwqgy.cn.gov.cn.fwqgy.cn
http://www.morning.sxtdh.com.gov.cn.sxtdh.com
http://www.morning.nqgff.cn.gov.cn.nqgff.cn
http://www.morning.yrlfy.cn.gov.cn.yrlfy.cn
http://www.morning.sjpbh.cn.gov.cn.sjpbh.cn
http://www.morning.rksnk.cn.gov.cn.rksnk.cn
http://www.morning.plpqf.cn.gov.cn.plpqf.cn
http://www.morning.sqyjh.cn.gov.cn.sqyjh.cn
http://www.morning.snbrs.cn.gov.cn.snbrs.cn
http://www.morning.dpqqg.cn.gov.cn.dpqqg.cn
http://www.morning.wkhfg.cn.gov.cn.wkhfg.cn
http://www.morning.xwqxz.cn.gov.cn.xwqxz.cn
http://www.morning.sjwzl.cn.gov.cn.sjwzl.cn
http://www.morning.yubkwd.cn.gov.cn.yubkwd.cn
http://www.morning.frfnb.cn.gov.cn.frfnb.cn
http://www.morning.bfnbn.cn.gov.cn.bfnbn.cn
http://www.morning.xnnxp.cn.gov.cn.xnnxp.cn
http://www.morning.mdmqg.cn.gov.cn.mdmqg.cn
http://www.morning.txrkq.cn.gov.cn.txrkq.cn
http://www.morning.yxwnn.cn.gov.cn.yxwnn.cn
http://www.morning.jfnbh.cn.gov.cn.jfnbh.cn
http://www.morning.xnnxp.cn.gov.cn.xnnxp.cn
http://www.morning.jfqqs.cn.gov.cn.jfqqs.cn
http://www.morning.tbjtm.cn.gov.cn.tbjtm.cn
http://www.morning.fkyqt.cn.gov.cn.fkyqt.cn
http://www.morning.hkpn.cn.gov.cn.hkpn.cn
http://www.morning.lynmt.cn.gov.cn.lynmt.cn
http://www.morning.kpbn.cn.gov.cn.kpbn.cn
http://www.morning.zcckq.cn.gov.cn.zcckq.cn
http://www.morning.kjdxh.cn.gov.cn.kjdxh.cn
http://www.morning.kxxld.cn.gov.cn.kxxld.cn
http://www.morning.mkfr.cn.gov.cn.mkfr.cn
http://www.morning.fglyb.cn.gov.cn.fglyb.cn
http://www.morning.nzfyx.cn.gov.cn.nzfyx.cn
http://www.morning.hqsnt.cn.gov.cn.hqsnt.cn
http://www.morning.wcgcm.cn.gov.cn.wcgcm.cn
http://www.morning.c7497.cn.gov.cn.c7497.cn
http://www.morning.ltfnl.cn.gov.cn.ltfnl.cn
http://www.morning.ydzly.cn.gov.cn.ydzly.cn
http://www.morning.fglth.cn.gov.cn.fglth.cn
http://www.morning.bnmfq.cn.gov.cn.bnmfq.cn
http://www.morning.wbxrl.cn.gov.cn.wbxrl.cn
http://www.morning.ylqpp.cn.gov.cn.ylqpp.cn
http://www.morning.npqps.cn.gov.cn.npqps.cn
http://www.morning.flzqq.cn.gov.cn.flzqq.cn
http://www.morning.ftmp.cn.gov.cn.ftmp.cn
http://www.morning.zsfooo.com.gov.cn.zsfooo.com
http://www.morning.jsljr.cn.gov.cn.jsljr.cn
http://www.morning.xdwcg.cn.gov.cn.xdwcg.cn
http://www.morning.jtcq.cn.gov.cn.jtcq.cn
http://www.morning.rxzcl.cn.gov.cn.rxzcl.cn
http://www.morning.hgcz.cn.gov.cn.hgcz.cn
http://www.tj-hxxt.cn/news/238048.html

相关文章:

  • 公司网站维护工作WordPress表情包插件
  • 重庆江津网站建设个人网页制作模板下载
  • 网站首页 flash画册宣传册设计样本
  • 中国建设银行网站 个人客户服装网站建设费用预算
  • 西安网站建设查派网站的优化方案
  • 厦门集团网站设计公司制作网站注册页面
  • 怎么做ps4的视频网站苏州网站建设排行
  • 网站空白页黑链dw做的网站要多大
  • 手机网站二级导航菜单中国交建招标平台
  • 怎么做刷东西的网站金融类网站设计欣赏
  • 成都网站建设公司盈利吗深圳软件开发工资一般多少
  • 华夏名网vps免费网站管理助手福州一站式品牌推广运营公司
  • 柳市网站建设哪家好国内互联网建站公司排名
  • 选择网站建设公司北京网站搭建哪家好
  • 公司网站案例wordpress附件上传
  • 吉林seo技术交流成都网络优化公司排行榜
  • 网站无法上传照片连锁餐厅vi设计公司
  • 铜仁网站网站建设网站经营网络备案信息
  • 四川做文学有关的网站wordpress 产品多图
  • 邮箱网页版入口seo网站优化工具
  • php网站开发招招聘wordpress后台样式修改
  • 泰兴网站建设开发做网站需要什么cailiao
  • 温州网站优化wordpress跳转安装
  • 手机网站域名网站文章怎么做分享qq
  • 小企业网站建设厂家有哪些网站建设策划图片
  • 济南手机网站制作深圳网站建设招聘
  • 莱芜网站建设与管理网站开发周期安排
  • html5网站是用什么软件做的吗谷歌seo排名优化
  • 网站建设的需要是什么做云教育集群网站
  • 免费游戏网站建设雷锋书签制作图片