Qt:QTableWidget/QTableView 在完整视口中交替行颜色 [英] Qt: QTableWidget/QTableView alternating row colors in full viewport

查看:105
本文介绍了Qt:QTableWidget/QTableView 在完整视口中交替行颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含来自数据库的数据行的 QTableView.但是,设置 setAlternatingRowColors(true) 只会交替包含数据的行颜色 - 表格的其余部分只是白色,这不是您期望的行为(例如,查看任何浏览器的书签列表 - 空行具有交替颜色).

I have a QTableView containing data rows from a database. However, setting setAlternatingRowColors(true) only alternates row colors that has data - the rest of the table is just white, which is not the behaviour you'd expect (look in the bookmark list of any browser, for example - empty rows has alternating colors).

有谁知道 Qt 提供的表格视图的替代方法或替代方法吗?我摆弄过样式表和项目委托,结果相同.

Does anyone know a workarund or an alternative to the table views supplied by Qt? I've fiddled with stylesheets and item delegates, same result.

推荐答案

为什么不使用 Qt QSS?它工作得很好.看看这里:http://www.qtcentre.org/threads/42211-QTableWidget-alternating-background-color?p=263046#post263046

Why don't you use Qt QSS for this? It working just fine. Have a look here : http://www.qtcentre.org/threads/42211-QTableWidget-alternating-background-color?p=263046#post263046

myTable->setAlternatingRowColors(true);
myTable->setStyleSheet("alternate-background-color: yellow;background-color: red;");

这篇关于Qt:QTableWidget/QTableView 在完整视口中交替行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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