Search code examples
c++qtqspinbox

add icon to QSpinBox


i need to draw something like this:

enter image description here

I've done button styling with stylesheet, but I cannot draw the warning icon. Is there some way to add it without reimplementation of paintEvent()? If it's possible only with changing paintevent, how should it look like?


Solution

  • I tried to add a QAction with an icon, but it couldn't be placed correctly. So the final solution is as simple as it is dumb, but it works:

    okSpinBoxStylesheet=            "QDoubleSpinBox{"
                                                "border: 1px solid grey;"
                                                "border-radius: 8px;"
                                                "margin-right: 20px;"
                                                "background-color: white;"
                                                "font: 12px Manrope;"
                                                "padding: 0px 0px 0px 8px;""}"
    alertSpinBoxStyleSheet=         "QDoubleSpinBox{"
                                                "border: 1px solid grey;"
                                                "border-radius: 8px;"
                                                "margin-right: 20px;"
                                                "background: url(:/rsc/img/alertBack.png);"
                                                "background-position: right center;"
                                                "font: 12px Manrope;"
                                                "padding: 0px 0px 0px 8px;""}"
                                        
    

    alertBack looks like this: enter image description here

    When I need an icon, I just apply proper stylesheet