Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # The following code is a severely reduced version of my application. Hopefully
- # it demonstrates the following problem.
- # Problem:
- # An extra resize event is being created after the subwindow should be fully
- # realized.
- # Select New->SubWindow
- # The extra resize event is printed to stdout.
- # AFAIK, this only happens on Ubuntu(12.04)/Unity 2d or 3d
- import sys
- from PyQt4.QtCore import *
- from PyQt4.QtGui import *
- from PyQt4.QtCore import Qt as qt
- class GView(QGraphicsView):
- def __init__(self, parent=None):
- super(GView, self).__init__(parent)
- self.setScene(QGraphicsScene(QRectF(0, 0, 100, 100)))
- self.scene().addRect(50, 50, 10, 10)
- self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
- self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
- def fitAll(self):
- r = QRectF()
- for item in self.scene().items():
- r = r.united(item.boundingRect())
- self.fitInView(r, qt.KeepAspectRatio)
- def resizeEvent(self, e):
- print "resize", e.size()
- super(GView, self).resizeEvent(e)
- class AppWindow(QMainWindow):
- def __init__(self, parent=None):
- super(AppWindow, self).__init__(parent)
- self.mdiArea = QMdiArea(self)
- self.mdiArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
- self.mdiArea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
- self.setCentralWidget(self.mdiArea)
- # Comment the following four lines and click in the main window to
- # create a new subwindow. The extra resize event is not created.
- # So is the very presence of the menuBar creating the event?
- newMenu = self.menuBar().addMenu("&New")
- subWinAction = newMenu.addAction("&SubWindow")
- self.connect(subWinAction, SIGNAL("triggered(bool)"),
- self.onSubWindow)
- self.statusBar()
- def onSubWindow(self, b=False):
- view = GView()
- self.addSubWindow(view)
- view.fitAll()
- print "no resize should follow this comment"
- def addSubWindow(self, view):
- self.mdiArea.addSubWindow(view)
- view.setAttribute(Qt.WA_DeleteOnClose)
- subWin = self.mdiArea.currentSubWindow()
- if subWin and not subWin.isMaximized():
- view.show()
- else:
- view.showMaximized()
- def mousePressEvent(self, e):
- self.onSubWindow()
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- mainWin = AppWindow()
- mainWin.show()
- app.exec_()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement