Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Create customized button
Forum Updated to NodeBB v4.3 + New Features

Create customized button

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jkprog
    wrote on 6 Jun 2017, 22:07 last edited by
    #1

    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

    https://www.shutterstock.com/image-vector/metallic-on-off-button-led-lights-103383638?irgwc=1&utm_medium=Affiliate&utm_campaign=Graphic resources SL&utm_source=39422

    J 1 Reply Last reply 7 Jun 2017, 05:30
    0
    • J jkprog
      6 Jun 2017, 22:07

      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

      https://www.shutterstock.com/image-vector/metallic-on-off-button-led-lights-103383638?irgwc=1&utm_medium=Affiliate&utm_campaign=Graphic resources SL&utm_source=39422

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 7 Jun 2017, 05:30 last edited by J.Hilk 6 Jul 2017, 05:31
      #2

      @jkprog

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

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      4

      1/2

      6 Jun 2017, 22:07

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved