QListWidget
1.失去焦点背景颜色,代码设置全选的时候,背景会是白色,需要设置失去焦点背景颜色。(设置焦点,会出现白转化成设置背景色,效果不好)
QPalette p;
p.setColor(QPalette::Inactive,QPalette::Highlight,QColor(51,153,255));
p.setColor(QPalette::Inactive,QPalette::HighlightedText,QColor(Qt::white));
p.setColor(QPalette::Inactive,QPalette::Text,QColor(Qt::white));
lwItems->setPalette(p); 去掉选择虚线框
MyListWidgetDelegate *listWidgetDelegate=new MyListWidgetDelegate(lwItems);
lwItems->setItemDelegate(listWidgetDelegate);
void DataDlg::createMiddleListView()
{ lwItems=new QListWidget();
lwItems->setSelectionMode(QAbstractItemView::MultiSelection);
lwItems->setEditTriggers(QAbstractItemView::SelectedClicked);
QPalette p;
p.setColor(QPalette::Inactive,QPalette::Highlight,QColor(,,));
p.setColor(QPalette::Inactive,QPalette::HighlightedText,QColor(Qt::white));
p.setColor(QPalette::Inactive,QPalette::Text,QColor(Qt::white));
lwItems->setPalette(p);
lwItems->setIconSize(QSize(,));
lwItems->setObjectName("lwItems");
MyListWidgetDelegate *listWidgetDelegate=new MyListWidgetDelegate(lwItems);
lwItems->setItemDelegate(listWidgetDelegate);
addExportItems();
contentLayout->addWidget(lwItems); }
添加数据
void DataDlg::addExportItems()
{
isExportData=true;
lwItems->clear();
btnImportExport->setText(exportText);
for(int i=;i<ExportFieldsCount;i++)
{
lwItems->addItem(ExportFields[i].fields);
setListWidgetIcon(i,false);
} }
选择触发事件
void DataDlg::listWidgetEvent(QListWidgetItem *clickedItem)
{ bool isSeleced=clickedItem->isSelected(); if(isSeleced==true)
{
clickedItem->setIcon(QIcon(":/res/icons/images/checkbox_checked.png")); }
else
{
clickedItem->setIcon(QIcon(":/res/icons/images/checkbox_unchecked.png")); } }
设置全选或者取消全选
void DataDlg::onSelectAll()
{
isSelectAll=!isSelectAll; int itemCount=lwItems->count();
for(int i=;i<itemCount;i++)
{
lwItems->item(i)->setSelected(isSelectAll); setListWidgetIcon(i,isSelectAll);
} }
添加图标
void DataDlg::setListWidgetIcon(int row,bool isChecked)
{
if(isChecked)
{
lwItems->item(row)->setIcon(QIcon(":/res/icons/images/checkbox_checked.png"));
}
else
{
lwItems->item(row)->setIcon(QIcon(":/res/icons/images/checkbox_unchecked.png")); } }
取出选中的值
int selectedCount=lwItems->selectedItems().count();
if(selectedCount==)
{
return;
} QString selectedText="";
for(int i=;i<selectedCount;i++)
{ selectedText=lwItems->selectedItems().at(i)->text();
}
2. 去掉选择虚线框
#ifndef MYLISTWIDGETDELEGATE_H
#define MYLISTWIDGETDELEGATE_H #include <QObject>
#include<QItemDelegate>
#include<QPen>
#include<QPainter>
#include<QBrush>
#include<QStyledItemDelegate> #include<QDebug> class MyListWidgetDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit MyListWidgetDelegate(QObject *parent = ); protected:
void paint(QPainter *painter,const QStyleOptionViewItem &option, const QModelIndex &index) const; private: signals: public slots:
}; #endif // MYLISTWIDGETDELEGATE_H
#include "mylistwidgetdelegate.h" MyListWidgetDelegate::MyListWidgetDelegate(QObject *parent) : QStyledItemDelegate(parent)
{ }
void MyListWidgetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{ QStyleOptionViewItem itemOption(option);
if(itemOption.state & QStyle::State_HasFocus)
{
itemOption.state = itemOption.state ^ QStyle::State_HasFocus;
} //调用默认委托
QStyledItemDelegate::paint(painter,itemOption,index); QPen pen;
pen.setColor(QColor(,,));
pen.setStyle(Qt::DotLine);
painter->setPen(pen);
painter->drawLine(itemOption.rect.bottomLeft(),itemOption.rect.bottomRight()); }
qss
QListWidget#lwItems{
color:#FFFFFF;
font:16pt "DejaVu Sans";
background-color:#;
margin:2px;
padding-left:10px;
padding-right:10px;
border: 1px solid #32435E;
}
QListWidget#scaleItemsList,QListWidget#connectedIPList{
color:#FFFFFF;
font:16pt "DejaVu Sans";
background-color:#;
margin:20px;
border: 1px solid #32435E;
}
QListWidget::item{
border:solid #;
border-width:0px 0px 1px 0px;
padding:10px 0px 10px 15px;
margin:0px 5px 0px 5px;
}
QListWidget::item:selected {
background: qlineargradient(x1: , y1: , x2: , y2: ,
stop: #6A848C, stop: 1.0 #0F9EAF);
}
QListWidget::item:selected:!active {
border-width: 0px ;
}
QListWidget::item:selected:active {
border-width: 0px;
}
QListWidget的更多相关文章
- Pyqt QListWidget之缩略图列表
QListWidget 可以设置模型setViewMode 当setViewMode值为QListView.IconMode 表示Icon模式 以下代码来自Pyqt Example #!/usr/b ...
- Pyqt QListWidget 展示系统环境变量
今天学习了下Pyqt的 QListWidget 控件 我们先看下这个图片 这张图片就是典型的listWidget效果,我们今天就仿这样布局新建个ListWidget 在网上找了个关于QListWidg ...
- 列表框QListWidget类
QListWidget类也是GUI中常用的类,它从QListView下派生: class Q_GUI_EXPORT QListWidget : public QListView { Q_OBJECT ...
- Pyqt在QListWidget中添加右键菜单
Pyqt 的资料奇少, 攻破难点之后, 就在这里记一下笔记. QListWidget 是继承 QWidget 的, 所以 QListWidget 是有右键菜单的, 从文档上可以找到 QWidget 上 ...
- QPushButton 与 QListWidget 的按键响应
在Qt中添加按钮或表格控件时需要添加其按键响应,一般来说有两种方法,一种是直接实现其响应函数,第二种是自己写一个响应函数,然后用Qt的信号槽将它们连接起来.愚以为第一种方法更为简单一些. 声明这些控件 ...
- QListWidget特别简单,但有两种添加item的方式
虽然特别简单,但是对于小白来说,还是有必要过一下脑子和眼睛,当然还得过手(江湖传言:眼过千变,不如手过一遍),所以记录在此: #include "tablewidgetxxx.h" ...
- QListWidget代码刷新界面
我有一个特殊效果要求实现(其实很弱智,也变成特殊效果,汗一下自己):两个QRadioButton切换的时候,让旁边的QListWidget自动变化不同的背景色.想了很多办法: 1. 控件自己刷新,不行 ...
- QListWidget方式显示缩略图
最近在工作中经常遇到了一个问题就是把把文件夹中的图片全部以缩略图的形式显示出来,刚开始的时候一头雾水,不知道怎么办,经过在网上查资料,发现QListWidget控件可以实现图片的缩略图显示,但是不知道 ...
- qt model/view 架构基础介绍之QListWidget
# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' from PyQt4.QtGui import * from Py ...
随机推荐
- nodejs 相关
1.错误 fs.js:543 return binding.rename(pathModule._makeLong(oldPath), 上传图片->图片改名->保存->在页面显示该图 ...
- C# 对象 序列化 XML
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
- Windows10的快捷键和新功能你利用了多少?
win10快捷键大全大家可以来了解一下,今天小编带来了win10常用快捷键,很多朋友喜欢使用快捷键来操作电脑,那么Windows10系统有哪些新的快捷键呢• 贴靠窗口:Win +左/右> Win ...
- CF456B Fedya and Maths 找规律
http://codeforces.com/contest/456/problem/B CF#260 div2 B Fedya and Maths Codeforces Round #260 B. F ...
- [译]了解AngularJS $resource
原文: https://learnable.com/books/angularjs-novice-to-ninja/preview/understanding-angularjs-resource-e ...
- JavaScript-也来谈--闭包
闭包,以前研究过,可能是当初理解的不够透彻,现在又忘了,(给自己一个台阶下`-...)毕竟js一直没怎么用, 为了防止自己过段时间再忘了,写篇重要的闭包重点, 这样时不时也能温习下知识,不用每次想了解 ...
- Intent和Activity知识点总结
1.Intent的跳转传值2.Intent的隐式启动(用于不同应用中)与显示启动(同一应用中)3.Activity的生命周期 void onCreate()——Activity已经被创建完毕,创 ...
- IIS 您要访问的网页有问题,无法显示!
提示:您要访问的网页有问题,无法显示.HTTP 500 – 内部服务器错误.”的问题解决方案! IIS服务器出现错误的原因很多,请尝试以下操作:1.查看网站属性——文档看看启用默认文档中是否存在:in ...
- POJ 1845 Sumdiv
快速幂+等比数列求和.... Sumdiv Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 12599 Accepted: 305 ...
- Ubuntu 14 安装 “宋体,微软雅黑,WPS Office的symbol、wingdings、wingdings 2、wingdings 3、webding字体,Consolas雅黑混合版编程字体” 等 Windows 7 下的字体
Windows平台下,“宋体”.“微软雅黑”.“Courier New(编程字体)”用的比较多,看的也习惯了.那如何在 Ubuntu下也安装这些字体呢? 操作步骤如下: 第一步:从 Windows 7 ...