2013-10-15 116 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; 
} 
相关问题