maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   How to set a Qt form to portrait orientation in PyQt? (https://talk.maemo.org/showthread.php?t=57428)

kojacker 2010-06-29 21:26

How to set a Qt form to portrait orientation in PyQt?
 
Im trying to set the orientation of a simple test Gui to portrait and I thought by adding

self.ui.setAttribute(Qt.WA_Maemo5PortraitOrientati on, True)

to the main.py file that would do it. Unfortunately it doesn't seem to be that simple. Once things go past being dead simple then Im in trouble, could someone more familiar point me to the problem and how I can correct it? Many thanks :)

Code:

#!/usr/bin/python2.5
import sys
from PyQt4 import QtGui,QtCore
from portraitTest import *

class MyForm(QtGui.QMainWindow):
        def __init__(self, parent=None):
                #build parent user interface
                QtGui.QWidget.__init__(self, parent)
                self.ui = Ui_MainWindow()
                self.ui.setupUi(self)
                try : self.ui.setAttribute(Qt.WA_Maemo5PortraitOrientation, True)
                except:print("Cannot set orientation to portrait")

                       

if __name__ == "__main__":
        app = QtGui.QApplication(sys.argv)
        myapp = MyForm()
        myapp.show()
        sys.exit(app.exec_())


mece 2010-06-29 21:52

Re: How to set a Qt form to portrait orientation in PyQt?
 
Quote:

Originally Posted by kojacker (Post 734640)
Im trying to set the orientation of a simple test Gui to portrait and I thought by adding

self.ui.setAttribute(Qt.WA_Maemo5PortraitOrientati on, True)

to the main.py file that would do it. Unfortunately it doesn't seem to be that simple. Once things go past being dead simple then Im in trouble, could someone more familiar point me to the problem and how I can correct it? Many thanks :)

Code:

#!/usr/bin/python2.5
import sys
from PyQt4 import QtGui,QtCore
from portraitTest import *

class MyForm(QtGui.QMainWindow):
        def __init__(self, parent=None):
                #build parent user interface
                QtGui.QWidget.__init__(self, parent)
                self.ui = Ui_MainWindow()
                self.ui.setupUi(self)
                try : self.ui.setAttribute(Qt.WA_Maemo5PortraitOrientation, True)
                except:print("Cannot set orientation to portrait")

                       

if __name__ == "__main__":
        app = QtGui.QApplication(sys.argv)
        myapp = MyForm()
        myapp.show()
        sys.exit(app.exec_())



hmm.. I import differently, because I don't feel like typing QtGui and such everywhere. This seems to work:
Code:

#!/usr/bin/python2.5
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
# from portraitTest import *

class MyForm(QMainWindow):
        def __init__(self, parent=None):
                #build parent user interface
                QWidget.__init__(self, parent)
#                self.ui = Ui_MainWindow()
#                self.ui.setupUi(self)
                try : self.setAttribute(Qt.WA_Maemo5PortraitOrientation, True)
                except:print("Cannot set orientation to portrait")
                       

if __name__ == "__main__":
        app = QApplication(sys.argv)
        myapp = MyForm()
        myapp.show()
        sys.exit(app.exec_())

(I didn't have your other stuff so I quoted them out)

kojacker 2010-06-30 00:19

Re: How to set a Qt form to portrait orientation in PyQt?
 
Thank you for your help Mece :)

I finally got it working by removing the "ui" from self.ui.setAttribute(Qt.WA_Maemo5PortraitOrientati on, True), so it now reads self.setAttribute.......

One thing that kinda irritates me is that when I minimize the application window, to see the multitasking view, it goes back into trying to display the form in landscape view so it looks wrong in the small preview pane. Once I click on it again, it expands and goes back into portrait. Is this normal behaviour?

mece 2010-06-30 11:54

Re: How to set a Qt form to portrait orientation in PyQt?
 
Quote:

Originally Posted by kojacker (Post 734809)
Thank you for your help Mece :)

I finally got it working by removing the "ui" from self.ui.setAttribute(Qt.WA_Maemo5PortraitOrientati on, True), so it now reads self.setAttribute.......

One thing that kinda irritates me is that when I minimize the application window, to see the multitasking view, it goes back into trying to display the form in landscape view so it looks wrong in the small preview pane. Once I click on it again, it expands and goes back into portrait. Is this normal behaviour?

It's normal. The dashboard doesn't support portrait.


All times are GMT. The time now is 03:22.

vBulletin® Version 3.8.8