2017-06-02 87 views
1

如果可能,我如何使用樣式表屬性(CSS)Qt設計?在Qt設計中設計QGroupBox

enter image description here

我嘗試使用下面的CSS:

QGroupBox { 
    border: 1px solid gray; 
    border-color: #FF17365D; 
    margin-top: 27px; 
    font-size: 14px; 
    border-radius: 15px; 
} 

QGroupBox::title { 
    subcontrol-origin: margin; 
    subcontrol-position: top center; 
    padding: 5px 8000px 5px 8000px; 
    background-color: #FF17365D; 
    color: rgb(255, 255, 255); 
} 

但我發現了這樣的結果:

enter image description here

我使用Qt 5.3。

回答

0

根據這裏找到的討論https://forum.qt.io/topic/80053/styling-qgroupbox-in-qt-design/8恐怕不可能使用QGroupBox(沒有設置固定填充到QGroupBox::title)達到預期結果。

因此,作爲一種變通方法,通過渦流的建議,我已經添加了一個垂直佈局和裏面,我已經加入一個QLabel(頂部)和一個QFrame(底部)和設置以下CSS

QLabel { 
    qproperty-alignment: AlignCenter; 
    border: 1px solid #FF17365D; 
    border-top-left-radius: 15px; 
    border-top-right-radius: 15px; 
    background-color: #FF17365D; 
    padding: 5px 0px; 
    color: rgb(255, 255, 255); 
    max-height: 25px; 
    font-size: 14px; 
} 
QFrame { 
    border: 1px solid #FF17365D; 
    border-bottom-left-radius: 15px; 
    border-bottom-right-radius: 15px; 
} 

結果可以看到如下:

enter image description here