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.2k 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 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.HilkJ 1 Reply Last reply
    0
    • J jkprog

      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.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #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

      • Login

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