Question

When I QApplication::setStyleSheet() with the following stylesheet

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;
}

all buttons size is truncated to the size of the text. For example the OK buttons became squared. The effect is the same with any other stylesheet I tried on QPushButton. How to set buttons stylesheet without affecting their default size?

Was it helpful?

Solution

I don't think you can mess with the borders or padding without affecting the widget's default size. You can set min-width though.

From the docs: 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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top