欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

QGroupBox样式表使用

程序员文章站 2022-04-16 23:35:58
...

一、设置border后标题下沉

解决方法:通过设置样式表

QGroupBox
{
border: 2px solid red;
border-radius:5px;
margin-top:2ex;//文字在方框中位置的偏离度
font-family:楷体;
font:bold 28px;

}

QGroupBox::title
{
subcontrol-origin:margin;
subcontrol-position:top center;
padding:0 3px;
}

其实能改变title下沉就 margin-top和padding。

QGroupBox样式表使用

QGroupBox样式表使用

QGroupBox样式表使用

QGroupBox样式表使用

二、设置子项样式:

边框色、选项高度、下拉按钮图标

 network_type->setStyleSheet("QComboBox{border:1px solid gray;}"
  "QComboBox QAbstractItemView::item{height:20px;}" //下拉选项高度 设置的下拉项的样式
  "QComboBox::down-arrow{image:url(:/icon/arrowdown);}" //下拉箭头
  "QComboBox::drop-down{border:0px;}"); //下拉按钮

QComboBox {
    border: 1px solid gray;
    border-radius: 3px;
    padding: 1px 18px 1px 3px;
    min-width: 6em;
}
 
QComboBox:editable {
    background: white;
}
 
QComboBox:!editable, QComboBox::drop-down:editable {
     background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                 stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
                                 stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
}
 
/* QComboBox gets the "on" state when the popup is open */
QComboBox:!editable:on, QComboBox::drop-down:editable:on {
    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                stop: 0 #D3D3D3, stop: 0.4 #D8D8D8,
                                stop: 0.5 #DDDDDD, stop: 1.0 #E1E1E1);
}
 
QComboBox:on { /* shift the text when the popup opens */
    padding-top: 3px;
    padding-left: 4px;
}
 
QComboBox::drop-down {
    subcontrol-origin: padding;
    subcontrol-position: top right;
    width: 15px;
 
    border-left-width: 1px;
    border-left-color: darkgray;
    border-left-style: solid; /* just a single line */
    border-top-right-radius: 3px; /* same radius as the QComboBox */
    border-bottom-right-radius: 3px;
}
 
QComboBox::down-arrow {
    image: url(/usr/share/icons/crystalsvg/16x16/actions/1downarrow.png);
}
 
QComboBox::down-arrow:on { /* shift the arrow when popup is open */
    top: 1px;
    left: 1px;
}

 

相关标签: Qt