Qt之樣式表QRadioButton詳細(xì)制作方法

前言
制作不易 多多支持
點(diǎn)贊關(guān)注 萬分感謝
個(gè)人經(jīng)驗(yàn)分享,望各位少走彎路
日后如果有新發(fā)現(xiàn),我會實(shí)時(shí)更新這個(gè)專欄
Q群:732513891?

QRadioButton

單選按鈕是在一個(gè)控件內(nèi)如果存在多個(gè)單選按鈕,那么在點(diǎn)擊一個(gè)按鈕的同時(shí),會取消其他按鈕的點(diǎn)選狀態(tài)。


QRadioButton{
?spacing:12px; ?
?color: rgb(255, 255, 255); ?
?background-color: rgba(165, 205, 255,125); ?
?border:1px outset rgb(255, 255, 255); ?
?border-radius:8px;
?padding:4px;
}
spacing是選擇框與文字之間的間距,文字為白色、背景顏色為天藍(lán)色透明度為125、邊框?yàn)?px的凹陷白色邊框、圓角為8px。
/*鼠標(biāo)放在按鈕上方*/
QRadioButton:hover { ?
?background-color: rgba(165, 205, 255,80%); ?
?border:2px outset rgba(36, 36, 36,0);
}
繼承QRadioButton開始的樣式并且添加,背景色為天藍(lán)色,提升透明度到80%,增加邊框?yàn)?px的凹陷透明邊框。
/*鼠標(biāo)點(diǎn)擊按鈕*/
QRadioButton:pressed { ?
?background-color: rgba(165, 205, 255,90%); ?
?border:4px outset rgba(36, 36, 36,0);
}
繼承QRadioButton開始的樣式并且添加,背景顏色透明度提升至90%,增加4px透明邊框。



QRadioButton{
?spacing:12px; ?
?color: rgb(255, 255, 255); ?
?background-color: rgba(165, 205, 255,125); ?
?border:1px outset rgb(255, 255, 255); ?
?border-radius:8px;
?padding:4px; ? ?
?text-align: center center; }
QRadioButton::indicator {
?padding-left:12px; ? ?
?width: 32px; ? ?
?height: 32px; ? ?
?left: 0px; ? ?
?right: 0px; ? ?
?top: 0px; ? ?
?bottom:0px; image: url(:/svg/img/svg/對號1.png); }
QRadioButton::indicator:hover { image: url(:/svg/img/svg/對號1 (2).png); } QRadioButton::indicator:pressed { image: url(:/svg/img/svg/對號1 (1).png); }
帶有icon、改變選擇框樣式、并且添加動作和間距。

不同狀態(tài)下??梢赃x擇不同樣式的狀態(tài)。
同樣的可以選擇自己喜歡的字體樣式。
/*選擇框未選中狀態(tài)*/
QRadioButton::indicator:unchecked { ? ?
?image: url(./image1.png);
}
/*選擇框鼠標(biāo)懸浮在未選中狀態(tài)*/
QRadioButton::indicator:unchecked:hover{ ? ?
?image: url(./image2.png);
}
/*選擇框鼠標(biāo)點(diǎn)擊未選中狀態(tài)*/
QRadioButton::indicator:unchecked:pressed { ? ?
?image: url(./image3.png);
}
/*選擇框選中狀態(tài)*/
QRadioButton::indicator:checked { ? ?
?image: url(./image4.png);
}
/*選擇框鼠標(biāo)懸浮在選中狀態(tài)*/
QRadioButton::indicator:checked:hover{ ? ?
?image: url(./image5.png);
}
/*選擇框鼠標(biāo)點(diǎn)擊在選中狀態(tài)*/
QRadioButton::indicator:checked:pressed { ? ?
?image: url(./image6.png); ? ?
?font-family: "Microsoft YaHei";
?font-size: 14px; font-style: italic;
?font-weight: bold;
?font: bold italic 18px "Microsoft YaHei";
}

????????那么Radiobutton就大概涵蓋這些,如果有遺漏請大家私信我,后續(xù)如果有發(fā)現(xiàn)新的玩法,會及時(shí)更新文章,希望大家多多關(guān)注點(diǎn)贊支持我。后續(xù)我會把其他控件的相關(guān)用法也寫出來。如果有深入學(xué)習(xí)和交流可以加群,群里有很多小伙伴可以一起討論問題。
?PyQt5學(xué)習(xí)愛好群主群:732513891(已滿)
PyQt5學(xué)習(xí)愛好群二群:937759168(已滿)
PyQt5學(xué)習(xí)愛好群三群:757679170
謝謝觀看
