[PyQt] Rotate QMainWindow 180deg

Maurizio Berti maurizio.berti at gmail.com
Fri May 11 11:59:15 BST 2018


You are getting it wrong: there can be only one central widget, and
obviously setting it for a QGraphicsProxyWidget doesn't make any sense.
Use the QGraphicsView as the central widget, then add the Browser_Widget to
its scene.
This has some drawbacks, expecially in your case: the widget will not have
direct access to the main window (and vice versa), which is most important
for layout and size reasons.
A partial solution might be to set the minimum size of the QGraphicsView
viewport to the minimumSizeHint of the Browser_Widget and implement the
resizeEvent of the QGraphicsView to notify the QGraphicsProxyWidget about
the size changes.
To prevent graphics, layout and alignment problems, set the frameShape of
the QGraphicsView to NoFrame and the scrollbar policy to scrollBarAlwaysOff.
Also, be aware that subclasses of QAbstractScrollArea (expecially item
views such as QListView, etc) have issues when used within a proxy widget,
most of them regarding mouse events. In my experience I had to reimplement
wheel events, some QHeaderView methods and other things related to mouse
hovering. And remember that popup widgets like QComboBoxes will show their
views within the scene, so if you have popup views that go outside the
"main" widget margins, they will be outside the graphics scene, thus will
not be completely shown.

Good luck! ;-)
Maurizio

2018-05-11 11:37 GMT+02:00 Rob <rob at pixelinspiration.net>:

> Hi,
>
> For mad reasons I've been asked to see if I can get an app to toggle itself
> by 180 degrees. Bit of googling came up with these two posts (in C++):
>
> daringfireball.org/blog/rotating-qt-apps-in-literally-6-lines-of-code.html
> https://forum.qt.io/topic/30230/solved-rotating-a-whole-ui/3
>
> Which both suggest the same approach using QGraphicsProxyWidget,
> QGraphicsScene and QGraphicsView which I've tried to implement like this
> (very cut down code):
>
> class MainWindow(QMainWindow):
>     def __init__(self, url):
>
>         self.browserWidget = Browser_Widget(self, url)
>         self.setCentralWidget(self.browserWidget)
>
>         self.scene = QGraphicsScene()
>         self.view = QGraphicsView(self)
>         self.proxy = self.scene.addWidget(self.centralWidget())
>         self.view.setScene(self.scene)
>         self.view.show()
>         self.view.rotate(180)
>
> Which gives me this small white rectangle at the top left:
> <http://python.6.x6.nabble.com/file/t380167/pyqt1.jpg>
>
> Thanks for any thoughts.
>
> Cheers,
> Rob
>
>
>
> --
> Sent from: http://python.6.x6.nabble.com/PyQt-f1792048.html
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt




-- 
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
http://www.jidesk.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180511/e948fe01/attachment.html>


More information about the PyQt mailing list