Skip to content
  • 0 Votes
    8 Posts
    2k Views
    P

    @LeLev Thanks , I will try the same .

  • 0 Votes
    1 Posts
    712 Views
    No one has replied
  • 0 Votes
    8 Posts
    4k Views
    Chris KawaC

    Well yes, but you're painting that color with alpha over whatever widget is under the button, since the event filter is called before paint event of the button and you return true from it so the button's paint event is never actually called. To see the button painted underneath you need to actually call the paint event of the button manually before you overpaint it with your color.

    Unrelated comments:

    You seem to have a very bad habit of just casting types with a C cast to whatever you think you need at the moment. I'm referring to the QWidget *widget = (QWidget *)object; cast in the eventFilter. If I used any non-widget QObject derived type with your class it would compile successfully and crash at runtime. There's a isWidgetType() method on a QObject that you can test with before casting. Also please don't use C style casts. It's just plain evil and you will cause bugs with it. Either to yourself or other people that use your classes. There's a lot safer qobject_cast for QObject derived types that will return nullptr that you can test for if the type can't be cast.

    Painting in response to a timer with interval of 10ms makes no sense on almost any of user's machines. The typical display is ticking at 60Hz (i.e. little over 16ms) so anything lower than that is just giving Qt more work in filtering out the update requests you are flooding it with. Displays with a higher refresh rate are still very rare and even on them there's not gonna be a noticeable difference if you stick to 60Hz animation.

    Using == operator on a floating point numbers is on borderline of being a bug. You should practically never do that unless you're actually testing floating number stability, which is like super rare. Use non-strict comparisons (< and >) or just stick to fixed point integers for steps like that.

  • 0 Votes
    2 Posts
    2k Views
    mrjjM

    @pmh4514

    maybe you can use the QDesktopWidget

    int QDesktopWidget::screenNumber(const QWidget * widget = 0) const Returns the index of the screen that contains the largest part of widget, or -1 if the widget not on a screen.