Search code examples
c++qtstylesqwidgetqpushbutton

Adding styles to QPushButton


I have created a qpushbutton in the source file ".cpp":

QPushButton * btn = new QPushButton("Click me");

and now I want to add styles to it. Like changing the background, adding border-radius, changing the cursor, and so on.


Solution

  • This works fine for me:

    btn->setObjectName("mybtn");
    btn->setStyleSheet(QString(""
                             "#mybtn{background-color: #182848; border-radius: 5px; border: 1px solid transparent; color: white;}"
                             "#mybtn:hover{background-color: white; border-color: #182848; color: #182848;}"
                             ));