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. Refresh QPushButton with mouse position
Qt 6.11 is out! See what's new in the release blog

Refresh QPushButton with mouse position

Scheduled Pinned Locked Moved General and Desktop
18 Posts 4 Posters 8.9k 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.
  • K Offline
    K Offline
    kamac
    wrote on last edited by
    #8

    Here's a preview of what's happening:

    !https://dl.dropbox.com/s/hw925d952uj41hm/button.gif(button)!

    Here's the code I am using when the window is closing, trying to clear the button's focus (doesn't work, as you can see)

    @void ConfigureWindow::closeEvent(QCloseEvent *event)
    {
    event->ignore();
    m_titlebar->buttonClose->clearFocus();
    this->hide();
    }@

    1 Reply Last reply
    0
    • T3STYT Offline
      T3STYT Offline
      T3STY
      wrote on last edited by
      #9

      The QWidget::onClose() event is not triggered when you hide a widget. Instead,the "QWidget::onHide()":http://qt-project.org/doc/qt-5/qwidget.html#hide event is triggered. Put your code in this event and try again :-)

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kamac
        wrote on last edited by
        #10

        It is triggered. Here's what buttonClose does:

        @connect( buttonClose, SIGNAL( clicked() ), parent, SLOT( close() ) );@

        Just to make sure, I've placed a display message box code to see if it really got executed -> it did.

        As you can see in the code posted below, I am ignoring close event, and instead I call this->hide() from there.

        1 Reply Last reply
        0
        • T3STYT Offline
          T3STYT Offline
          T3STY
          wrote on last edited by
          #11

          The main issue is still the same, the button does not have a chance to loose focus before the window is hidden.
          As a workaround, can you move focus on another object before hiding?

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kamac
            wrote on last edited by
            #12

            I probably could, but I don't quite understand why it doesn't have a chance to lose focus before the window is hidden.

            @m_titlebar->buttonClose->clearFocus();
            this->hide();@

            this kinda gives it the chance, no? Or does it have to be inside onHide event? (the clearFocus)

            1 Reply Last reply
            0
            • T3STYT Offline
              T3STYT Offline
              T3STY
              wrote on last edited by
              #13

              I think the problem there is not focus at all, but actually, the widget painting. Seems like after hiding, closing or minimizing a widget, the paint event just stops drawing.
              consider this simple code:
              @#include <QApplication>
              #include <QWidget>
              #include <QPushButton>

              int main(int argc, char *argv[]){
              QApplication a(argc, argv);

              QPushButton button;
              button.resize(200, 100);
              button.show();

              QObject::connect(&button, SIGNAL(clicked()), &button, SLOT(showMinimized()));

              return a.exec();
              }@
              When you press the button it will minimize the window. As you click on the icon in the taskbar the window is restored and the button looks normal. but if you look at the taskbar preview you can see the window is still painted with the pressed button state (right side of the image).
              !http://img.networkdigitale.com/di/0ZRM/preview.png(preview)!

              I don't have a solution, but I may suggest to force repaint the widget by calling the painter or something....

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kamac
                wrote on last edited by
                #14

                Right, now tell me this isn't Qt's fault that there is no clear way to fix this, or even that it happens at all.

                I've tried to repaint the widget, but it didn't work.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  arsinte_andrei
                  wrote on last edited by
                  #15

                  you can write a bug about this.. for sure the developers will want to get rid of it in Qt 5.4. Indeed is looking like a bug - or maybe an optimisation for low memory... hm.. who know... but any way some window flags suppose to be to repaint before hiding or on showing. any way for me this is a strange behaviour.

                  1 Reply Last reply
                  0
                  • T3STYT Offline
                    T3STYT Offline
                    T3STY
                    wrote on last edited by
                    #16

                    I don't think it's literally a bug. When an object is hidden it doesn't make sense to try drawing it because there is nothing to be shown to the user. Altough, the fact that an object is not correctly updated when restoring it, might be a qt issue. You should check this more thoroughly, see if there is something in your code that causes this behavior. I'm sure it would have been noticed by more people if it was a qt issue.

                    The pushbutton object you're using, is it a custom class derived from QPushButton? If so, can you share the code so people can check it?

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      kamac
                      wrote on last edited by
                      #17

                      It's a QPushButton with CSS style applied.

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        kamac
                        wrote on last edited by
                        #18

                        I've fixed it by doing this:

                        @void ConfigureWindow::closeEvent(QCloseEvent *event)
                        {
                        event->ignore();
                        // You have to completely remove the widget, add it again and wait about 10ms, then hide window
                        // to clear hover state on the close button nicely.
                        m_titlebar->HideTitlebar(); // this removes and deletes all buttons
                        m_titlebar->DisplayTitlebar(); // this initializes and adds them again
                        QTimer::singleShot(10, this, SLOT(finalizeClose()));
                        }

                        void ConfigureWindow::finalizeClose()
                        {
                        this->hide();
                        }@

                        This is an awkward, but working solution.

                        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