qt - How to make a child widget that stays at the same screen position when the parent widget is moved? -


i experimenting creating child widget stays @ same screen position when parent widget moved. should generate impression parent widget "views" underlying scene. following code illustrates want:

from pyqt4.qtgui import qapplication, qwidget, qpalette, qpainter pyqt4.qtcore import qt  class child(qwidget):     def __init__(self, parent=none):         super(child, self).__init__(parent)         pal = qpalette(qt.white)         self.setautofillbackground(true)         self.setpalette(pal)      def paintevent(self, event):         painter = qpainter(self)         painter.fillrect(25, 25, 50, 50, qt.red)         painter.end()  class parent(qwidget):     def __init__(self, parent=none):         super(parent, self).__init__(parent)         self.child = child(self)         self.child.setgeometry(100, 100, 100, 100)      def moveevent(self, event):         diffpos = event.pos() - event.oldpos()         self.child.move(self.child.pos() - diffpos)  if __name__ == "__main__":     import sys     app = qapplication(sys.argv)     parent = parent()     parent.setgeometry(100, 100, 300, 300)     parent.show()     sys.exit(app.exec_()) 

however, flickers! think due fact end painting twice. since child widget stays @ same position, not need redrawn. have experimented wa_staticcontents, qeventfilter, etc try tell qt should not redraw child widget, not successful.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -