2013-10-15 109 views
2

當我的QApplication :: setStyleSheet()具有以下樣式表如何設置影響按鈕大小的QPushButton樣式表?

QPushButton { 
    border-radius: 2px; 
    padding: 0.2em 0.2em 0.3em 0.2em; 
    border: 1px solid rgb(100, 100, 100); 
    background: qlineargradient(x1:0, y1:0, x2:0, y2:1, 
            stop:0 #f4f4f4, stop:0.1 #8F8F8F, stop:1 #7B7B7B); 
    color: white; 
} 

所有按鈕的大小被截斷爲文本的大小。例如OK按鈕變平方。效果與我在QPushButton上嘗試的任何其他樣式表相同。如何設置按鈕樣式表而不影響其默認大小?

回答

2

我不認爲你可以在不影響窗口部件默認大小的情況下邊框或邊框填充。但您可以設置min-width

從文檔:If this property is not specified, the minimum width is derived based on the widget's contents and the style.

QPushButton { 
    border-radius: 2px; 
    padding: 0.2em 0.2em 0.3em 0.2em; 
    border: 1px solid rgb(100, 100, 100); 
    background: qlineargradient(x1:0, y1:0, x2:0, y2:1, 
            stop:0 #f4f4f4, stop:0.1 #8F8F8F, stop:1 #7B7B7B); 
    color: white; 
    min-width: 70px; 
} 
相關問題