如何设置QHeaderview选中后的背景色

smq 2016-04-01 08:54:24
我创建了个QTableview,在选中某个Section后,我想让HeaderView的背景色改变,试验了好多种方法都不行,高手指点下
...全文
721 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
东莞某某某 2016-04-06
  • 打赏
  • 举报
回复
给一个参考的模板
QTableView
{
    border: 1px solid #444;
    gridline-color: #6c6c6c;
    background-color: #201F1F;
}


QTableView, QHeaderView
{
    border-radius: 0px;
}

QTableView::item:pressed, QListView::item:pressed, QTreeView::item:pressed  {
    background: #78879b;
    color: #FFFFFF;
}

QTableView::item:selected:active, QTreeView::item:selected:active, QListView::item:selected:active  {
    background: #3d8ec9;
    color: #FFFFFF;
}


QHeaderView
{
    border: 1px transparent;
    border-radius: 2px;
    margin: 0px;
    padding: 0px;
}

QHeaderView::section  {
    background-color: #3A3939;
    color: silver;
    padding: 4px;
    border: 1px solid #6c6c6c;
    border-radius: 0px;
    text-align: center;
}

QHeaderView::section::vertical::first, QHeaderView::section::vertical::only-one
{
    border-top: 1px solid #6c6c6c;
}

QHeaderView::section::vertical
{
    border-top: transparent;
}

QHeaderView::section::horizontal::first, QHeaderView::section::horizontal::only-one
{
    border-left: 1px solid #6c6c6c;
}

QHeaderView::section::horizontal
{
    border-left: transparent;
}


QHeaderView::section:checked
 {
    color: white;
    background-color: #5A5959;
 }

 /* style the sort indicator */
QHeaderView::down-arrow {
    image: url(:/qss_icons/rc/down_arrow.png);
}

QHeaderView::up-arrow {
    image: url(:/qss_icons/rc/up_arrow.png);
}
just59277 2016-04-05
  • 打赏
  • 举报
回复
QHeaderView::section:checked{ background: #ffffff; } 直接设置QSS 就行了吧?你是要改 headerview的背景 还是说要改整个这一列的背景?
务观逍遥子 2016-04-01
  • 打赏
  • 举报
回复
我有个想法,关联槽 connect( horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(headerClicked(int)) ); 在headerClicked(Int)中设置 QHeaderView.setStyleSHeet(),来改变其背景色。 不知道这样可以不可以达到你的要求。

16,240

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧