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. QAction not triggered during polish/unpolish, and button disappears
Forum Updated to NodeBB v4.3 + New Features

QAction not triggered during polish/unpolish, and button disappears

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 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.
  • S Offline
    S Offline
    sangelsen
    wrote on last edited by
    #1

    Hi,

    I am having an issue with a push button I have implemented. The button inherits from QAction. When the button is in a certain state, I am flashing the button using simple timers. Colors are implemented using QStyleSheet.

    The problem is that if I click the button -just- before the next flash, it will both:

    1. Be unresponsive (triggered() is not executed)
    2. Size of button reduced to practically invisible.
      a) If the button has 1 row of text it will become totally invisible
      b) If the button has 2 rows of text it will be slightly invisible, but still clickable

    At the next flash-timer event, the button will re-appear.

    The flasher function that is executed at each flash:

    void QExtWidgetSimpleFlasher::setFlash(bool flashOn)
    {
        m_widget->setProperty("flash", flashOn);
    
        m_widget->style()->unpolish(m_widget);
        m_widget->style()->polish(m_widget);
    }
    

    The "setFlash" function executes in 0.5 ms in average.

    I suspect it has something to do with the unpolish/polish routine, but can't find the exact problem.

    The same problem happens when the button is clicked extremely fast multiple times (the button will be hidden in the same way as the flashing-button). But it happens very frequently with the flashing button. Very easy to consistently reproduce by timing the click to just before the next flashing update. So, something to do with the button paint handling vs click events?

    Anyone has any ideas?

    Best regards,
    Stian

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

      Hi,

      Out of curiosity, why are you making a button from a QAction ? There are already several button classes. You can associate a QAction with a button.

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sangelsen
        wrote on last edited by sangelsen
        #3

        Hi,

        Edit:
        I am working with some legacy code, so it's a custom push button class. The "widgetForActions" is casted both as QAbstractButton and QToolButton. They are children of a QToolBar. The classes include a QPushButton, but I can't see it's actually actually implemented somewhere..

        Anyway, there might be some issues related to the custom implementation, but I haven't found anything.

        My main question is more specifically if dynamic stylesheet updates inhibits button action or has any other side-effect.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sangelsen
          wrote on last edited by sangelsen
          #4

          I just reduced the flashing frequency to 100ms. When clicking, the button disappears and QAction is not triggered on any event. The only thing I'm doing during the flash-sequence is updating the stylesheet as described in first post.

          Edit: I experiemented with disable/enable around the polish events. Doing this, the button does no longer disappear. Yay! But QAction is still not triggered.

          void QExtWidgetSimpleFlasher::setFlash(bool flashOn)
          {
              m_widget->setProperty("flash", flashOn);
          
              m_widget->style()->unpolish(m_widget);
          
              m_widget->setDisabled(true);
              m_widget->style()->polish(m_widget);
              m_widget->setEnabled(true);
          }
          
          1 Reply Last reply
          0
          • S Offline
            S Offline
            sangelsen
            wrote on last edited by
            #5

            Not solved, but found a work-around. It is not very satisfactory, but I can't see another option right now.

            The function:

            m_widget->style()->polish(m_widget);
            

            is definitely interfering with the "triggered" event from QAction.

            I have found out that this works, somehow:

            void QExtWidgetSimpleFlasher::setFlash(bool flashOn)
            {
                m_widget->setProperty("flash", flashOn);
            
                m_widget->style()->unpolish(m_widget);
                m_widget->update();
            }
            

            For some reason, unpolish is able to update button colors and text font. It updates everything I need except size. So I have to create a configurable width and height, and also call

                    widget->setFixedWidth(config.width);
                    widget->setFixedHeight(config.height);
            

            This gives me the desired end-result and button behaviour.

            If anyone comes along and know what is up with the polish function, please let me know.

            Best regards,
            Stian

            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