【QSS样式表 - ⑨】:QGroupBox控件样式

QGroupBox控件样式

  1. 子控件
    在这里插入图片描述
  2. 常用属性
    在这里插入图片描述

QSS示例

  1. 新建一个 QMainWIndow 窗口,在其中放入四个 QGroupBox 控件。

    QGroupBox {
    	background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #E0E0E0,
    	stop: 1 #FFFFFF);
    
    	border: 2px solid gray;
    	border-radius: 5px;
    	font: 20px;
    }
    

    在这里插入图片描述

  2. 分别设置这四个 QGroupBox 可观察其区别。

    QGroupBox {
    	background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #E0E0E0,
    	stop: 1 #FFFFFF);
    	border: 2px solid gray;
    	border-radius: 5px;
    	font: 20px;
    }
    
    #groupBox{
    	margin-top: 3ex;	 /*表示margin距border有3个距离*/
    }
    
    #groupBox::title{
    	subcontrol-origin: margin;	/* 和margin的起点对齐 */
    	subcontrol-position: top center;
    	background-color: red;
    }
    
    #groupBox_2{
    	padding-top: 5ex;	/*与groupBox_3进行对比,可看出区别*/
    }
    
    #groupBox_2::title{
    	subcontrol-origin: padding; /* 和padding开始对齐*/
    	subcontrol-position: top left;
    	background-color: yellow;
    }
    
    #groupBox_3{
    	padding-top: 5px;
    }
    
    #groupBox_3::title{
    	subcontrol-origin: content;  /*与内容对齐*/
    	subcontrol-position: top left;
    	background-color: blue;
    }
    
    #groupBox_4::title{
    	subcontrol-origin: border; /*与边框对齐*/
    	subcontrol-position: top left;
    	background-color: green;
    }
    

    在这里插入图片描述

setStyleSheet(R"( addNewRule { background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(245, 247, 250, 255), stop:1 rgba(221, 230, 237, 255)); } QLabel { font-size: 18px; color: #333333; min-width: 60px; padding-top: 0px; padding-bottom: 0px; text-align: left; } styleLineEdit { min-height: 24px; font-size: 16px; border: 1px solid #cccccc; border-radius: 4px; padding: 4px; background-color: white; } styleLineEdit:error { border: 1px solid #e64942; } QComboBox { min-height: 80px; border: 1px solid #cccccc; border-radius: 4px; padding: 2px 20px 2px 8px; background-color: white; selection-background-color: #4a86e8; selection-color: white; font-size: 16px; } QComboBox::drop-down { subcontrol-origin: padding; subcontrol-position: top right; width: 20px; border-left-width: 1px; border-left-color: #cccccc; border-left-style: solid; border-top-right-radius: 4px; border-bottom-right-radius: 4px; background-color: #f0f0f0; } QComboBox::down-arrow { image: url(:/icons/down_arrow.png); width: 12px; height: 12px; } QComboBox QAbstractItemView { border: 1px solid #cccccc; border-radius: 4px; padding: 2px; background-color: white; selection-background-color: #4a86e8; selection-color: white; font-size: 16px; } QPushButton { min-height: 26px; font-size: 16px; font-weight: 500; border-radius: 4px; padding: 4px 16px; } QPushButton#m_ok { color: white; background-color: #4a86e8; border: 1px solid #4a86e8; } QPushButton#m_ok:hover { background-color: #3a76d8; } QPushButton#m_ok:pressed { background-color: #2a66c8; } QPushButton#m_cancel { color: #333333; background-color: #f0f0f0; border: 1px solid #cccccc; } QPushButton#m_cancel:hover { background-color: #e0e0e0; } QPushButton#m_cancel:pressed { background-color: #d0d0d0; } QTimeEdit { min-height: 20px; font-size: 16px; border: 1px solid #cccccc; border-radius: 2px; padding: 2px; background-color: white; } QGroupBox { font-size: 18px; color: #333333; border: 1px solid #cccccc; border-radius: 2px; padding: 5px; margin-top: 5px; } QGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; padding: 0 5px; } QCheckBox { font-size: 16px; color: #333333; } QRadioButton { font-size: 16px; color: #333333; } )");设置好看一些的颜色搭配,偏冷色
07-02
int main(int argc, char *argv[]) { QApplication a(argc, argv); //加载样式表 QFile file(":/css/index.css"); if (file.open(QFile::ReadOnly)) { QString qss = QLatin1String(file.readAll()); qApp->setStyleSheet(qss); file.close(); } //全局字体 QFont font("Arial", 10); a.setFont(font); //屏幕拖动 AppInit::Instance()->start(); mainWidget w; w.show(); return a.exec(); }* { color: #3d4150; } QPushButton { border-style: none;border: 1px solid #DCDFE6;border-radius: 6px;padding: 5px 10px;font-size: 13px; } QPushButton:hover { color: #ffffff; font-weight: bold; background-color: #fd839a; } QScrollBar:vertical { background:#f5f6f8; padding:0px; border-radius: 3px; width:6px; } QScrollBar::handle:vertical { background:#C0C4CC; border-radius: 3px; } QScrollBar::handle:vertical:hover { background:#909399; } QScrollBar::handle:vertical:pressed { background:#909399; } QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical, QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical { background:none; } QCheckBox, QRadioButton { font-size: 13px; } QComboBox, QLineEdit, QTextEdit, QTextBrowser, QTimeEdit, QDateEdit, QDateTimeEdit, QSpinBox, QDoubleSpinBox { background-color: #ffffff; border: 1px solid #DCDFE6; border-radius: 6px; padding: 5px 10px; font-size: 13px; } QTextEdit, QTextBrowser { padding-right: 3px; } QLineEdit:hover, QComboBox:hover, QTimeEdit:hover, QDateEdit:hover, QDateTimeEdit:hover, QSpinBox:hover, QDoubleSpinBox:hover { border: 1px solid #409EFF; } QComboBox::down-arrow { width:10px; height:10px; right:2px; image:url(:/icons/down.png); } QComboBox::drop-down { subcontrol-origin:padding; subcontrol-position:top right; width:15px; border-left-width:0px; border-left-style:solid; border-top-right-radius:3px; border-bottom-right-radius:3px; border-left-color:#242424; } QComboBox QAbstractItemView::item{ min-height:20px; min-width:10px; } QComboBox::drop-down:on{ top: 1px; } QTimeEdit::up-button, QDateEdit::up-button, QDateTimeEdit::up-button, QSpinBox::up-button, QDoubleSpinBox::up-button { width:10px; height:10px; image:url(:/icons/up.png); padding: 3px 8px 0px 0px; } QTimeEdit::down-button, QDateEdit::down-button, QDateTimeEdit::down-button, QSpinBox::down-button, QDoubleSpinBox::down-button { width:10px; height:10px; image:url(:/icons/down.png); padding: 0px 8px 3px 0px; } QTimeEdit::up-button:pressed, QDateEdit::up-button:pressed, QDateTimeEdit::up-button:pressed, QSpinBox::up-button:pressed, QDoubleSpinBox::up-button:pressed { top: -2px; } QTimeEdit::down-button:pressed, QDateEdit::down-button:pressed, QDateTimeEdit::down-button:pressed, QSpinBox::down-button:pressed, QDoubleSpinBox::down-button:pressed { bottom: -2px; } QTabWidget::pane{ border:1px solid #DCDFE6; border-radius: 6px; border-top-left-radius: 0px; background-color: #ffffff; selection-background-color:#ffffff; selection-color:#DCDFE6; alternate-background-color:#f2f1f5; gridline-color:#3d4150; } QTabBar::tab { border:1px solid #DCDFE6; border-top-left-radius: 6px; border-top-right-radius: 6px; font-size: 13px; background-color: #f2f1f5; padding: 2px 6px; } QTabWidget::pane:top { top:-1px; } QTabWidget::pane:bottom { bottom:-1px; } QTabWidget::pane:left { right:-1px; } QTabWidget::pane:right { left:-1px; } QTabBar::tab:selected { background-color: #ffffff; border-bottom: none; } QGroupBox { border: 1px solid #DCDFE6; border-radius: 6px; font-size: 13px; margin-top: 7px; } QGroupBox::title { subcontrol-origin: margin; subcontrol-position: top center; padding: 0px 5px 3px; } #w_bg { background-color: #f2f1f5; border-radius: 22px; } #w_menu { background-color: #f8f8f8; border-radius: 16px; } #btn_menu_item_1, #btn_menu_item_2, #btn_menu_item_3, #btn_menu_item_4, #btn_menu_item_5, #btn_menu_item_6 { background-color: #ffffff; border-radius: 5px; padding: 12px 0 0; } #btn_menu_item_1:hover, #btn_menu_item_2:hover, #btn_menu_item_3:hover, #btn_menu_item_4:hover, #btn_menu_item_5:hover, #btn_menu_item_6:hover { background-color: #f8f8f8; border: 1px solid #f0f0f0; } #lab_title { padding: 0 10px; } #btn_main_item_1, #btn_main_item_2, #btn_main_item_3, #btn_main_item_4 { padding: 8px 12px; color: #909399; border: none; } #btn_main_item_1:hover, #btn_main_item_2:hover, #btn_main_item_3:hover, #btn_main_item_4:hover { background-color: #ffffff; border-radius: 15px; color: #3d4150; } #btn_mine, #btn_setting, #btn_home, #btn_littleshow, #btn_logout { border: none; } #btn_mine:hover, #btn_setting:hover, #btn_home:hover, #btn_littleshow:hover, #btn_logout:hover { background-color: #eeeff4; border-radius: 10px; } #sw_main { background-color: #f8f8f8; border-radius: 16px; } #lab_mess_1, #lab_mess_2, #lab_mess_3, #lab_mess_4 { color: #C0C4CC; } #MyMessageBox QLabel { color: #3d4150; } #btn_mbox_btn01, #btn_mbox_btn02 { height: 16px; color: #fd839a; font-size: 14px; background-color: #f2f2f2; border: 1px solid #DCDFE6; border-radius: 13px; padding: 6px 20px; } #btn_mbox_btn01:hover, #btn_mbox_btn02:hover { color: #ffffff; font-weight: bold; background-color: #fd839a; }
07-05
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

街 三 仔

你的鼓励是我创作的最大动力~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值