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. StyleSheet set is slow
Qt 6.11 is out! See what's new in the release blog

StyleSheet set is slow

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.6k 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.
  • A Offline
    A Offline
    Abin
    wrote on last edited by
    #1

    HI,

    I tried to set the style sheet. It gets effected, but takes a second to update in UI.
    I am trying to change border on mouse press. I need to keep my widget pressed for a second for the change to appear

    @void PosButton::mouseReleaseEvent(QMouseEvent *event)
    {
    qDebug() << Q_FUNC_INFO << "Invoked";

    if(rect().contains(event->pos()))
    {
        qDebug() << Q_FUNC_INFO << "Emit click";
        emit clicked(this->objectName());
    }
    
    m_pBaseWidget->setStyleSheet("QFrame#baseWidget {"
                          "border: 1px solid black;"
                          "border-top-width: 0;"
                          "border-left-width: 0;"
                          "border-style: outset;}"
                  );
    
    qDebug() << Q_FUNC_INFO << "Exits";
    return;
    

    }

    void PosButton::mousePressEvent(QMouseEvent *event)
    {
    qDebug() << Q_FUNC_INFO << "Invoked";
    Q_UNUSED(event);

    m_pBaseWidget->setStyleSheet("QFrame#baseWidget {"
                          "border: 2px solid orange;"
                          "border-top-width: 0;"
                          "border-left-width: 0;"
                          "border-style: outset;}"
                  );
    
    qDebug() << Q_FUNC_INFO << "Exits";
    return;
    

    }@

    PosButton is derived from QWidget. I am trying to set style for the QFrame baseWidget inside it.

    Also I tried setting property and change but I'm not sure if the style sheet statement I use is in right way

    @PosButton[pressed="true"] QFrame#baseWidget
    {
    border: 2px solid orange;
    border-top-width: 0;
    border-left-width: 0;
    border-style: outset;
    }

    PosButton[pressed="false"] QFrame#baseWidget
    {
    border: 1px solid black;
    border-top-width: 0;
    border-left-width: 0;
    border-style: outset;
    }
    @

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

      Hi,

      Might be a silly question but, why don't you style a QPushButton ?

      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
      • A Offline
        A Offline
        Abin
        wrote on last edited by
        #3

        SGaist,

        I use this class as multiple types of buttons.. It has 4 labels of which one has image set on it. In total it is a customized button. So I am forced to use a custom widget instead of QPushButton.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Abin
          wrote on last edited by
          #4

          Thanks,

          I resolved this issue by setting a timer on the mouse release. The timeout will reset the style of the button

          @void PosButton::mouseReleaseEvent(QMouseEvent *event)
          {
          qDebug() << Q_FUNC_INFO << "Invoked";

          if(rect().contains(event->pos()))
          {
              qDebug() << Q_FUNC_INFO << "Emit click";
              emit clicked(this->objectName());
          }
          
          QTimer::singleShot(150, this, SLOT(styleTimeout()));
          
          qDebug() << Q_FUNC_INFO << "Exits";
          return;
          

          }

          void PosButton::mousePressEvent(QMouseEvent *event)
          {
          qDebug() << Q_FUNC_INFO << "Invoked";
          Q_UNUSED(event);

          m_pBaseWidget->setStyleSheet("QFrame#baseWidget {"
                                "border: 2px solid orange;"
                                "border-top-width: 0;"
                                "border-left-width: 0;"
                                "border-style: outset;}"
                        );
          
          qDebug() << Q_FUNC_INFO << "Exits";
          return;
          

          }

          void PosButton::styleTimeout()
          {
          qDebug() << Q_FUNC_INFO << "Invoked";

          if (NULL != m_pBaseWidget)
          {
              qDebug() << Q_FUNC_INFO << "set style";
              m_pBaseWidget->setStyleSheet("QFrame#baseWidget {"
                                    "border: 1px solid black;"
                                    "border-top-width: 0;"
                                    "border-left-width: 0;"
                                    "border-style: outset;}"
                            );
          }
          
          qDebug() << Q_FUNC_INFO << "Exits";
          return;
          

          }@

          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