随笔 - 632  文章 - 17  评论 - 54  阅读 - 92万

Qt给QRadioButton设置自定义样式

一、概述

  做一个好看的QRadioButton。可以选中,取消选中。

二、代码示例

  1.样式

复制代码
QRadioButton::indicator::unchecked {
    border-image: url(images/user_protocol_uncheck.webp);
}

QRadioButton::indicator::checked {
    border-image: url(images/user_protocol_checked.webp);
}

QRadioButton::indicator {
    width: 24px;
    height: 24px;
}
复制代码

  2.自定义RadioButton.h/RadioButton.cpp

复制代码
#include "RadioButton.h"

RadioButton::RadioButton(QWidget *parent)
    : QRadioButton(parent)
{
    //这里设置一个默认的样式
    QString css = StyleHelper::getStyleSheet(StyleConfig::COMMON_RADIOBUTTON_DEFAULT());
    this->setStyleSheet(css);
}

RadioButton::~RadioButton()
{

}
复制代码

  3.使用

    //RadioButton
    RadioButton* rb = new RadioButton();
    rb->move(5, et3->y() + et3->height() + 5);

  4.效果

 

posted on   飘杨......  阅读(1105)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· NetPad:一个.NET开源、跨平台的C#编辑器
· PowerShell开发游戏 · 打蜜蜂
· 凌晨三点救火实录:Java内存泄漏的七个神坑,你至少踩过三个!
历史上的今天:
2022-11-28 SDP字段解释一览表
2013-11-28 eclipse中查看安装的所有插件,并选择性的将其卸载
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

点击右上角即可分享
微信分享提示