Qt Widgets setStyleSheet

As I program the tablet environment, some widgets are too small for touch interaction. I want to do more QSpinBox buttons.

After some searching, I found that the only way is the setStyleSheet function, but then it is not very well explained how to use it. This link to the Qt link describes what I should pass to the setStyleSheet function, but it is not clear if I can use part of it or should I use all of this, even if I only want to change one thing.

In any case, using part of this or all the text, my QDoubleSpinBox looks by default after applying these settings. This was even more since I am drawing a miii file than now. Of course, he does not color his yellow background (only to test its operation) or makes the buttons larger.

I am using this function:

customizeSpinBox(ui.doubleSpinBoxDistanciaLocalizador); ui.doubleSpinBoxDistanciaLocalizador->setVisible(true); void MyClass::customizeSpinBox(QDoubleSpinBox *spinBox){ qApp->setStyleSheet("QSpinBox { border: 3px solid red; border-radius: 5px; background-color: yellow; }" "QSpinBox::up-arrow { border-left: 17px solid none;" "border-right: 17px solid none; border-bottom: 17px solid black; width: 0px; height: 0px; }" "QSpinBox::up-arrow:hover { border-left: 17px solid none;" "border-right: 17px solid none; border-bottom: 17px solid black; width: 0px; height: 0px; }" "QSpinBox::up-button { width: 80px; height: 77px; background-color: yellow; }" "QSpinBox::up-button:hover { width: 80px; height: 77px; background-color: yellow; }" "QSpinBox::down-arrow { border-left: 17px solid none;" "border-right: 17px solid none; border-top: 17px solid black; width: 0px; height: 0px; }" "QSpinBox::down-arrow:hover { border-left: 17px solid none;" "border-right: 17px solid none; border-top: 17px solid black; width: 0px; height: 0px; }" "QSpinBox::down-button { width: 80px; height: 77px; background-color: yellow; }" "QSpinBox::down-button:hover { width: 80px; height: 77px; background-color: yellow; }" ); 

}

Any help?

+4
source share
3 answers

First of all, this style code cannot work. Closing "}" is missing on some lines.

To set the minimum size of a QSpinBox, try the following: QSpinBox { border: 3px solid red; border-radius: 5px; background-color: yellow; min-width: 200px; min-height: 200px; } QSpinBox { border: 3px solid red; border-radius: 5px; background-color: yellow; min-width: 200px; min-height: 200px; }

Using this method, I got a big, ugly spinbox with this style:

 "QSpinBox { border: 3px solid red; border-radius: 5px; background-color: yellow; min-height: 150px; min-width: 150px; }" "QSpinBox::up-arrow { border-left: 17px solid none;" "border-right: 17px solid none; border-bottom: 17px solid black; width: 0px; height: 0px; }" "QSpinBox::up-arrow:hover { border-left: 17px solid none; " "border-right: 17px solid none; border-bottom: 17px solid black; width: 0px; height: 0px; }" "QSpinBox::up-button { min-width: 80px; min-height: 77px; background-color: yellow; }" "QSpinBox::up-button:hover { min-width: 80px; min-height: 77px; background-color: yellow; }" "QSpinBox::down-arrow { border-left: 17px solid none;" "border-right: 17px solid none; border-top: 17px solid black; width: 0px; height: 0px; }" "QSpinBox::down-arrow:hover { border-left: 17px solid none;" "border-right: 17px solid none; border-top: 17px solid black; width: 0px; height: 0px; }" "QSpinBox::down-button { min-width: 80px; min-height: 77px; background-color: yellow; }" "QSpinBox::down-button:hover { min-width: 80px; min-height: 77px; background-color: yellow; }" 

enter image description here

+3
source

Place a semicolon on the last line of the line in the stylesheet.

Use

 "QSpinBox::down-button:hover { width: 80px; height: 77px; background-color: yellow; };" 

instead

 "QSpinBox::down-button:hover { width: 80px; height: 77px; background-color: yellow; }" 
0
source

Sorry, I'm late. Check it out . I realized that both "subcontrol-origin: ..." and "subcontrol-position: ..." need to be set to the down button and the up button. I am using python + pyqt. Hope this helps you.

0
source

All Articles