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. What QICon state is used when QToolButton isDown?

What QICon state is used when QToolButton isDown?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 2.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.
  • B Offline
    B Offline
    buckler
    wrote on last edited by
    #1

    Hello,
    I am successfully using multiple QIcon states for various states of QToolButton. However, I cannot see how to use a different state when a button "isDown". I have done web searches and I see this discussed from time to time but have not yet found a direct answer on how to do this.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Doesn't the On/Off state do that ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      raven-worxR 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Doesn't the On/Off state do that ?

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by raven-worx
        #3

        @buckler
        I think this is not supported by default.

        Try the following example:

        #define COLOREDPIX(COLOR) QPixmap COLOR ## Pix(16,16); COLOR ## Pix.fill(Qt:: ## COLOR);
        ...
        COLOREDPIX(red);
        COLOREDPIX(yellow);
        COLOREDPIX(green);
        COLOREDPIX(blue);
        COLOREDPIX(black);
        COLOREDPIX(white);
        COLOREDPIX(magenta);
        COLOREDPIX(cyan);
        
        QIcon icon;
            icon.addPixmap(redPix, QIcon::Normal, QIcon::On);
            icon.addPixmap(yellowPix, QIcon::Disabled, QIcon::On);
            icon.addPixmap(greenPix, QIcon::Active, QIcon::On);
            icon.addPixmap(bluePix, QIcon::Selected, QIcon::On);
            icon.addPixmap(blackPix, QIcon::Normal, QIcon::Off);
            icon.addPixmap(whitePix, QIcon::Disabled, QIcon::Off);
            icon.addPixmap(magentaPix, QIcon::Active, QIcon::Off);
            icon.addPixmap(cyanPix, QIcon::Selected, QIcon::Off);
        
        QPushButton* button = new QPushButton;
            button->setIcon( icon );
            button->show();
        

        QIcon::Normal -> unfocused
        QIcon::Disabled -> disabled
        QIcon::Selected -> selected (maybe used in QGraphicsView, i don't know)
        QIcon::Active -> focused

        QIcon::On -> checked
        QIcon::Off -> unchecked

        A possible workaround - when you do not depend on the checked state of the button:

        void MyPushButton::paintEvent(QPaintEvent *)
        {
            QStylePainter p(this);
            QStyleOptionButton option;
            initStyleOption(&option);
            if( m_isPressed )
                  option.state |= QStyle::State_On;
            p.drawControl(QStyle::CE_PushButton, option);
        }
        

        Make sure you set the m_isPressed in the mouseButtonPress event handler to true and to false in the mouseButtonRelease event handler.
        This is also necessary for keyPress/Release for the space key.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        1
        • B Offline
          B Offline
          buckler
          wrote on last edited by
          #4

          Thank you both! Raven-worx confirms that while it isn't easy to do, yet it is possible to do!

          1 Reply Last reply
          0

          • Login

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