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. Custom button with custom states and images

Custom button with custom states and images

Scheduled Pinned Locked Moved General and Desktop
button custom s
4 Posts 2 Posters 3.6k Views
  • 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.
  • A Offline
    A Offline
    AdrienM
    wrote on 22 Jul 2015, 08:17 last edited by
    #1

    Hello,

    I am new at QT (I used another software called Altia Design for visualization), and I would like to make custom buttons. However I don't know where to start, what classes from QT to inherit in order to do what I want.

    The images of my button are stored in .png formats.

    Basically, it shall have the following states:

    • Unpressed.
    • Pressed.
    • Unpressed with a different icon (representing that the action performed behind the button is completed).
    • Unpressed locked (you cannot press it, again a different icon).

    My software shall be able to trigger any state, and also to display a custom animation (loading) around the button. It was really easy in the other software but I don't know where to start here. Any advise?

    Thank you in advance for your help.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 22 Jul 2015, 08:52 last edited by
      #2

      Qt uses a css-like syntax to determining apparence of the widgets, see http://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qpushbutton for an introductory example.

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AdrienM
        wrote on 22 Jul 2015, 09:15 last edited by
        #3

        Hello VRonin,

        Thank you for your answer. However, I already checked this page and as far as I understood stylesheets are used to change the appearance of an existing object. It doesn't change the logic behind the button (states, and triggers) . Am I correct?

        My expected behavior would be the following:

        1. The button is pressed then released (display pressed and release).
        2. The loading effect is displayed around the button (waiting for my software to perform the related actions).
        3. When the software has finished to perform the actions, the leading animation is stopped and hidden, and the button icon changes to another icon (loaded).
        4. If the user presses again the button, it comes back to step 1.

        Are Stylesheets sufficient to realize this behavior?

        Thanks

        1 Reply Last reply
        0
        • V Offline
          V Offline
          VRonin
          wrote on 22 Jul 2015, 09:47 last edited by
          #4

          Stylesheets can handle everything you said but the animation.
          To implement that I'd subclass QWidget and put a QPushButton and a QLabel on top of each other (manually or put them in the same cell of a QGridLayout), assign a QMovie vith the animation to the label and connect the QPushButton::clicked signal to QLabel::show slot.
          When the work is finished just call the QLabel::hide slot

          for the loaded/non loaded icon on the button you can either call QPushButton::setIcon() with a different icon or subclass QPushButton, add a Q_PROPERTY that stores the state of the button (loaded/non loaded) and let the stylesheet take care of setting the right icon

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          0

          1/4

          22 Jul 2015, 08:17

          • Login

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