QAction not triggered during polish/unpolish, and button disappears



  • 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


  • Lifetime Qt Champion

    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.



  • 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.



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


  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.