Create customized button
-
Hi, I am trying to create an on/off button. I want to make a button like as shown in the attached image file. I know how to make the round buttons but I am not sure how to make this one..
Secondly, when any button is pressed on my gui, it should be more prominent, that means it should be in its 3D form or the shiny look. I have attached the picture to make it more clear. Is it possible to do such formatting of buttons in QT? Also, all my buttons, except the on/off button contain images. And I want to give a 3D effect to all my buttons with the pictures attached.http://www.freepik.com/free-vector/shiny-modern-circles_840499.htm
-
Hi, I am trying to create an on/off button. I want to make a button like as shown in the attached image file. I know how to make the round buttons but I am not sure how to make this one..
Secondly, when any button is pressed on my gui, it should be more prominent, that means it should be in its 3D form or the shiny look. I have attached the picture to make it more clear. Is it possible to do such formatting of buttons in QT? Also, all my buttons, except the on/off button contain images. And I want to give a 3D effect to all my buttons with the pictures attached.http://www.freepik.com/free-vector/shiny-modern-circles_840499.htm
I believe QStyleSheet should provide you with all you need.
As it is a bit tricky to get into, as a potential beginner, here an example:
Replace the url with the actual path to the target pictures:QPushButton *btn-> = new QPushButton(); btn->show(); btn->setCheckable(true); btn->setStyleSheet( QPushButton{border-image:url(:/path/to/image.png);} QPushButton:pressed{border-image:url(:/path/to/image.png);} QPushButton:checked{border-image:url(:/path/to/image.png);} QPushButton:checked:pressed{border-image:url(:/path/to/image.png);} QObject::connect(qApp, &QApplication::aboutToQuit, btn, &QPushButton::deleteLater); );