Results 1 to 7 of 7

Thread: How to avoid redraw of widgets outside visibleRegion on update? [PyQt5]

  1. #1
    Join Date
    Aug 2018
    Posts
    9
    Qt products
    Qt5
    Platforms
    Unix/X11

    Question How to avoid redraw of widgets outside visibleRegion on update? [PyQt5]

    I have subclassed a widget, a QSlider, and styled it so it has large transparent margins. This makes it much easier to grab on a touchscreen. However, the margin extends under some buttons to the right of the slider. This causes the buttons to redraw when the slider is moved, which is very slow. If I make the slider narrow, so it does not have the margins, then it renders fast and the buttons do not redraw. I think I would like the margins to exist for the purposes of touch detection, but not for the purposes of dirty rect propagation.

    I tried to change the visible region the paint event, but it only affected the slider drawing itself - it did not affect the buttons being redrawn.
    Qt Code:
    1. def paintEvent(self, evt):
    2. clippedEvt = QPaintEvent(self.visibleRegion())
    3. super().paintEvent(clippedEvt)
    To copy to clipboard, switch view to plain text mode 
    So I downloaded the source code, and in qt-everywhere-opensource-src-5.7.1/qtbase/src/widgets/kernel/qwidget.cpp:10966, in the QWidget::update function, it looked like it was responsible for figuring out where the update rect was. I think it just uses the bounding box of the widget.

    I would like to use the visual bounding box, however, instead of the real one, for the purposes of repainting. To do this, I tried overriding the update function in my subclass, like this:
    Qt Code:
    1. def update(arg):
    2. print('update event', arg)
    To copy to clipboard, switch view to plain text mode 
    However, I can not get my slider to print update event. It appears it still uses the parent class' update event to schedule updates.

    So I tried overriding the rect function, because I see update uses that. I don't think this will work, since I bet this is also used for touch intersection calculation. But it is no matter, because it too has no effect.
    Qt Code:
    1. def rect(self):
    2. print('update rect')
    3. return QRect(30, 10, self.width()-30, self.height-10)
    To copy to clipboard, switch view to plain text mode 

    Is there another way to make my widgets, far away and above the transparent margin, not redraw themselves? Or have I taken the wrong approach?

    Thanks!
    –DDR

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to avoid redraw of widgets outside visibleRegion on update? [PyQt5]

    Neither QWidget::update() nor QWidget::rect() are "virtual" in C++, thus they cannot be overridden.

    How did you end up with the slider and button overlapping?
    Even if the slider's drawing is only occupying a part of its area, the layout should still have position the button outside of the slider's bounding box.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to avoid redraw of widgets outside visibleRegion on update? [PyQt5]

    the layout should still have position the button outside of the slider's bounding box.
    Sounds like maybe the OP isn't using layouts to position the widgets.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. #4
    Join Date
    Aug 2018
    Posts
    9
    Qt products
    Qt5
    Platforms
    Unix/X11

    Arrow Re: How to avoid redraw of widgets outside visibleRegion on update? [PyQt5]

    I couldn't figure out how to shift the slider to one side or the other, so I just made the slider wider than it needed to be and buried the unwanted space under some buttons to the side. (I wanted the hit rect of the slider handle to be larger than the visible handle, because I'm working with a questionable $12 touchscreen, so I added a bunch of invisible padding to it.)

    screenshot.png

    In this screenshot, we see the touch area drawn as green. (This is normally drawn transparent.) Even if you miss the slider by a small margin, you can still drag it without any issue. The green area used to extend out a few pixels to the left and right, so it was even easier to drag. However, this caused the text on the buttons to get redrawn so I narrowed it. But now it's harder to drag.


    Added after 6 minutes:


    Oh, sorry, missed your reply there.

    Quote Originally Posted by d_stranz View Post
    Sounds like maybe the OP isn't using layouts to position the widgets.
    That is correct. Proper layouts are both hard to use and glitchy in Qt Designer. I couldn't resize them, they often resized themselves to inappropriate dimensions, and they didn't survive save/load very reliably. Since I often found myself having to edit the XML output of Designer and reload, I switched to absolute positioning. Due to the fixed-size screen on the product the interface is for, this is acceptable.
    Last edited by DDR; 30th May 2019 at 00:11. Reason: Original post was duplicated after edit.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to avoid redraw of widgets outside visibleRegion on update? [PyQt5]

    Quote Originally Posted by DDR View Post
    I couldn't figure out how to shift the slider to one side or the other, so I just made the slider wider than it needed to be and buried the unwanted space under some buttons to the side.
    Shifting the slider might be possible with a stylesheet but it should definitely work with a custom style.

    Quote Originally Posted by DDR View Post
    Proper layouts are both hard to use and glitchy in Qt Designer.
    In Designer they require a bit of getting used to but they work very nicely in code.

    Quote Originally Posted by DDR View Post
    Due to the fixed-size screen on the product the interface is for, this is acceptable.
    Ah. And not needing translations either?

    In any case your type of UI looks like it would be much more a candidate for using QtQuick instead of QtWidgets.

    Cheers,
    _

  6. #6
    Join Date
    Aug 2018
    Posts
    9
    Qt products
    Qt5
    Platforms
    Unix/X11

    Post Re: How to avoid redraw of widgets outside visibleRegion on update? [PyQt5]

    Quote Originally Posted by anda_skoa View Post
    And not needing translations either?
    I think we should be able to do that with Widgets, shouldn't we? It seems to have a patina of translation stuff built around it.

    Quote Originally Posted by anda_skoa View Post
    In any case your type of UI looks like it would be much more a candidate for using QtQuick instead of QtWidgets.
    In our testing, our target CPU wasn't powerful enough to run QtQuick at a reasonable framerate. We don't have a functional GPU, so we're relying on slow software rendering to the framebuffer. So, while I'd love to… it's among the many things I can't have.
    Also, does QtQuick have a visual layout tool like Designer?

    Thanks,
    –DDR
    Last edited by DDR; 4th June 2019 at 02:21. Reason: This forum does not support astral plane utf8, apparantly. RIP my emoji.

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to avoid redraw of widgets outside visibleRegion on update? [PyQt5]

    Quote Originally Posted by DDR View Post
    I think we should be able to do that with Widgets, shouldn't we?
    Of course.

    I was just asking because you say you have fixed sizes.
    The moment you have translations that is no longer true.


    Quote Originally Posted by DDR View Post
    In our testing, our target CPU wasn't powerful enough to run QtQuick at a reasonable framerate. We don't have a functional GPU, so we're relying on slow software rendering to the framebuffer.
    Is that with the QQuick 2D render or using software rendered OpenGL?

    The former was specifically created for systems without GPU.
    There is even a research project for running QtQuick UIs on micro controllers

    Quote Originally Posted by DDR View Post
    Also, does QtQuick have a visual layout tool like Designer?
    There is a visual designer, however most people prefer to do the layouting in QtQuick manually. Either suing anchors or the layout types.

    Cheers,
    _

Similar Threads

  1. Replies: 0
    Last Post: 3rd October 2011, 14:36
  2. Replies: 6
    Last Post: 3rd September 2010, 20:21
  3. how to force widgets update
    By Onanymous in forum Newbie
    Replies: 5
    Last Post: 14th June 2010, 18:37
  4. Replies: 0
    Last Post: 7th August 2009, 17:10
  5. Avoid moving widgets
    By desch in forum Qt Programming
    Replies: 5
    Last Post: 9th April 2009, 07:27

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.