转载:https://www.cnblogs.com/csuftzzk/p/qss_combobox.html

转载:https://www.bbsmax.com/A/E35pLgRK5v/

转载:https://www.cnblogs.com/peterliang/p/3618820.html(QSplitter 拆分窗口)

转载:http://blog.sina.com.cn/s/blog_a6fb6cc90101i8it.html

Demo参考网上的例子,暂时记录下来,随后再整理

1.自定义combobox中的item控件

#include <QWidget>
#include <QLabel> class ComboboxItem : public QWidget
{
Q_OBJECT public:
ComboboxItem(QWidget *parent);
~ComboboxItem(); void setLabelContent(const QString & str); signals:
void chooseAccount(const QString&); private:
QLabel* m_img;
QLabel* m_label;
};
#include "ComboboxItem.h"
#include <QHBoxLayout> ComboboxItem::ComboboxItem(QWidget *parent)
: QWidget(parent)
{
m_img = new QLabel(this);
m_label = new QLabel(this);
m_img->setStyleSheet("QLabel{background: rgb(255, 0, 0)}");
m_img->setFixedSize(, ); QHBoxLayout* layout = new QHBoxLayout(this); layout->addWidget(m_img);
layout->addWidget(m_label);
layout->setContentsMargins(, , , ); setLayout(layout);
} ComboboxItem::~ComboboxItem()
{
} void ComboboxItem::setLabelContent(const QString & str)
{
m_label->setText(str);
}

2.自定义代理

#include <QStyledItemDelegate>

class NoFocusFrameDelegate :public QStyledItemDelegate
{
Q_OBJECT
public:
NoFocusFrameDelegate(QObject* parent = );
~NoFocusFrameDelegate(); virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
#include "NoFocusFrameDelegate.h"

NoFocusFrameDelegate::NoFocusFrameDelegate(QObject* parent /*= 0*/)
{ } NoFocusFrameDelegate::~NoFocusFrameDelegate()
{ } void NoFocusFrameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItem view_option(option);
if (view_option.state & QStyle::State_HasFocus) {
view_option.state = view_option.state ^ QStyle::State_HasFocus;
} QStyledItemDelegate::paint(painter, view_option, index);
}

3.主窗口中使用

#include <QtWidgets/QMainWindow>
#include "ui_QMyCombobox.h" class QListWidget; class QMyCombobox : public QMainWindow
{
Q_OBJECT public:
QMyCombobox(QWidget *parent = Q_NULLPTR); public slots: void onChooseAccount(const QString& str); private:
Ui::QMyComboboxClass ui; QListWidget* m_listWidget;
};
#include "QMyCombobox.h"
#include <QListWidget>
#include "NoFocusFrameDelegate.h"
#include "ComboboxItem.h" QMyCombobox::QMyCombobox(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this); m_listWidget = new QListWidget(this); // 设置子项目代理,否则下拉框选项周围会出现虚线框
m_listWidget->setItemDelegate(new NoFocusFrameDelegate(this));
ui.comboBox->setEditable(true);
ui.comboBox->setModel(m_listWidget->model());
ui.comboBox->setView(m_listWidget); // 在下拉框中添加5个选项
for (int i = ; i < ; ++i)
{
ComboboxItem* item = new ComboboxItem(this);
item->setLabelContent(QString("Account") + QString::number(i, ));
connect(item, SIGNAL(chooseAccount(const QString&)), this, SLOT(onChooseAccount(const QString&)));
QListWidgetItem* widgetItem = new QListWidgetItem(m_listWidget);
m_listWidget->setItemWidget(widgetItem, item);
}
} void QMyCombobox::onChooseAccount(const QString& str)
{
ui.comboBox->setCurrentText(str);
}

最后效果:

Qt 组合框QComboBox的定制的更多相关文章

  1. Qt Style Sheet实践(二):组合框QComboBox的定制

    导读 组合框是一个重要且应用广泛的组件,一般由两个子组件组成:文本下拉单部分和按钮部分.在许多既需要用户选择.又需要用户手动输入的应用场景下,组合框能够很好的满足我们的需求.如我们经常使用的聊天软件Q ...

  2. Qt Style Sheet实践(二):组合框QComboBox的定制(24K纯开源)——非常漂亮

    组合框是一个重要且应用广泛的组件,一般由两个子组件组成:文本下拉单部分和按钮部分.在许多既需要用户选择.又需要用户手动输入的应用场景下,组合框能够很好的满足我们的需求.如我们经常使用的聊天软件QQ登录 ...

  3. 第15.41节、PyQt(Python+Qt)入门学习:输入部件QComboBox组合框功能详解

    专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 一.概述 Designer中输入工具部件中的Combo Box组合框与 ...

  4. 组合框里添加复选框的方法(使用勾选的假象,用图片代替而已,并非QT原生支持)

    组合框可以看作是列表框和文本框的组合,因其占据的空间少,使用操作方便,常被界面设计人员用于界面开发设计中,在有限个输入的条件下,组合框常用来代替文本框,这样从用户使用角度来看,更趋人性化,所见即所得. ...

  5. 第三十四章、PyQt中的输入部件:QComboBox组合框功能详解

    专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 一.概述 Designer中输入工具部件中的Combo Box组合框与 ...

  6. PyQt(Python+Qt)学习随笔:字体writingSystem、ProportionalFonts、MonospacedFonts的含义以及QFontComboBox字体组合框详解

    专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 一.引言 在介绍QFontComboBox之前,我们先简单介绍一下字体 ...

  7. Qt自定义控件之可伸缩组合框(GroupBox)控件

    摘要 本文基于QGroupBox扩展了一种可以伸缩的组合框,正常状态下,组合框处于收缩状态,内部的控件是隐藏的:需要的时候,可以将组合框进行伸展,并将内部控件显示出来. 正文 实现的代码比较简单,主要 ...

  8. 组合框QGroupBox

    样式: 注意:内部必须使用布局控件 import sys from PyQt5.QtCore import Qt from PyQt5.QtGui import QPixmap from PyQt5. ...

  9. combox组合框设置高度

    组合框设置高度 转载 2013年10月24日 22:54:03 1033 MFC进行界面编程时,组合框CComboBox控件在可视化设计组件的时候是无法进行高度编辑的,但是我们在实际的项目中经常需要定 ...

随机推荐

  1. Charles弱网测试转载

    一.破解版安装 工具好用是好用,但有个蛋疼的地方,非开源,非开源也就算了,还来个试用30分钟,当时的我就中这招了, 试用了之后发现这工具确实好用,对于测试工程师来说兼抓包定位协议类bug.设置网络阀来 ...

  2. Laravel - Method [xxx] does not exist on [xxx]

    The controller is existing, and the method 'test' exist on 'App\Http\Controllers\Admin\IndexControll ...

  3. java String字符串编码类型转换

    /** * 前后端数据乱码问题 * 解决办法1: * 乱码原因:一编一解码型不一致导致. * [main description] * @param {[type]} String[] args [d ...

  4. Emmagee的基本使用

    Emmagee的基本使用 注意:目前最新版本为2.5.1:由于谷歌限制仅支持安卓7.0以下版本: 一.Emmagee介绍 Emmagee是一个简单易上手的Android性能监测工具,主要用于监测单个A ...

  5. Python 字符集

    什么是字符? 1.在Python中,字符串中的内容都是字符. 2.什么是字符编码(encode)和字符集(charset)? 计算机只能识别数值,而字符不能识别,为了让计算机能处理字符,必须将字符和数 ...

  6. (七)Kubernetes Service资源

    Service概述 为什么要使用Service Kubernetes Pod是平凡的,由Deployment等控制器管理的Pod对象都是有生命周期的,它们会被创建,也会意外挂掉.虽然它们可以由控制器自 ...

  7. git使用过程中的若干问题笔记

    1.关于本地分支创建之后,如何在远程创建同名分支并完成本地分支到远程分支的push 首先创建本地库分支以dev为例 然后输入命令git push --set-upstream origin dev / ...

  8. 利用form.submit提交表单导出文件到客户端浏览器, 提示下载!

    本来是想利用ajax提交json数据到服务端, 让服务端生成一个excel文件并提示客户端浏览器下载的. 但是搞了很久发现ajax方式是无法触发浏览器弹出文件下载的. 网上很多的方案都是说利用form ...

  9. 命令查询windows&Linux系统版本信息

    Linux 查询系统名字输入"cat /proc/version",说明正在运行的内核版本uname -rwindows 查询系统名字win+r -> winversyste ...

  10. Virtual DOM--react

    Consider a DOM made of thousands of divs. Remember, we are modern web developers, our app is very SP ...