找回密码
 立即注册
收起左侧

QListWidget 如何设置item 选中的样式

4
回复
9181
查看
[复制链接]
累计签到:182 天
连续签到:1 天
来源: 2019-9-12 14:03:51 显示全部楼层 |阅读模式
5Qter豆


最佳答案

查看完整内容

QSS 是可以办到的 ~可以百度
回复

使用道具 举报

累计签到:742 天
连续签到:1 天
2019-9-12 14:03:52 显示全部楼层
QSS 是可以办到的 ~可以百度
回复

使用道具 举报

累计签到:375 天
连续签到:1 天
2019-9-12 16:21:37 显示全部楼层
是这样吗?设置选中的背景色和字体颜色
  1. connect(ui->listWidget,SIGNAL(currentRowChanged(int)),this,SLOT(moved(int)));

  2. void MainWindow::moved(int a);
  3.         ui->listWidget->item(a)->setBackground(QColor(50,50,50));
  4.         ui->listWidget->item(a)->setTextColor(Qt::white);
复制代码


点评

我想用QSS的,不是用代码设置的  详情 回复 发表于 2019-9-17 09:09
回复

使用道具 举报

累计签到:182 天
连续签到:1 天
2019-9-17 09:06:54 显示全部楼层
QListView {
     show-decoration-selected: 1; /* make the selection span the entire width of the view */
}

QListView::item:alternate {
     background: #EEEEEE;
}

QListView::item:selected {
     border: 1px solid #6a6ea9;
}

QListView::item:selected:!active {
     background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                 stop: 0 #ABAFE5, stop: 1 #8588B2);
}

QListView::item:selected:active {
     background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                 stop: 0 #6a6ea9, stop: 1 #888dd9);
}

QListView::item:hover {
     background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                 stop: 0 #FAFBFE, stop: 1 #DCDEF1);
}
可以了
回复

使用道具 举报

累计签到:182 天
连续签到:1 天
2019-9-17 09:09:22 显示全部楼层
驲屋安阮 发表于 2019-9-12 16:21
是这样吗?设置选中的背景色和字体颜色

我想用QSS的,不是用代码设置的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了