maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   pyqt Menu's - need an example please? (https://talk.maemo.org/showthread.php?t=48819)

noobmonkey 2010-03-31 08:52

pyqt Menu's - need an example please?
 
Hi everyone, i have searched everywhere, tried irc and really not getting anywhere.

I'm trying to implement a very simple menu in pyqt (for the n900).
It just needs one button that runs a function.

IMy code probably looks a bit confused by now as i have tried lots of things... i've got to a point with no errors, but also no menu when i click the title bar.

Any help would be greatly appreciated.

Code:

self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
        self.menubar.setObjectName("menubar")

        self.menuFile = QtGui.QMenu(self.menubar)
        self.menuFile.setObjectName("menuFile")
        MainWindow.setMenuBar(self.menubar)

        self.actionupdateall = QtGui.QAction(MainWindow)
        self.actionupdateall.setObjectName("actionupdateall")
       
        self.menuFile.addSeparator()
        self.menuFile.addAction(self.actionupdateall)
        self.menubar.addAction(self.menuFile.menuAction())

        self.menubar.addAction(self.menuFile.menuAction())
        self.menuFile.setTitle(QtGui.QApplication.translate("MainWindow", "File", None, QtGui.QApplication.UnicodeUTF8))

(P.s. sorry if it makes no sense in the code - but really confused)

attila77 2010-03-31 09:22

Re: pyqt Menu's - need an example please?
 
Note that in Qt4.5 the menu *must* be called "fremantle" to be displayed. Qt4.6 will display them all, but not in a backwards compatible way (they will appear as "fremantle/[optionname]"). Also, I think you want to use setText (objectName is something different) :)

krk969 2010-03-31 09:27

Re: pyqt Menu's - need an example please?
 
Quote:

Originally Posted by noobmonkey (Post 589385)
I'm trying to implement a very simple menu in pyqt (for the n900).
It just needs one button that runs a function.

have a look at a previous post of mine for a hildon menu.
Not sure if that is what you really need though. That gives you a hildon menu by clicking the title bar of your Qt app.

noobmonkey 2010-03-31 09:55

Re: pyqt Menu's - need an example please?
 
thanks krk969, thats in c though :| :|

trying atilla's recommendation with no luck so far...

also been trying
#create menu
fremantle = MainWindow.menuBar().addMenu("File");
act = fremantle.addAction("Update")
QtCore.QObject.connect(act, QtCore.SIGNAL("triggered()"), self.updateAll)


Nothing seems to work :|

attila77 2010-03-31 10:03

Re: pyqt Menu's - need an example please?
 
Code:

#!/usr/bin/python

from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import SIGNAL, SLOT
import sys

appt=QtGui.QApplication(sys.argv)

MainWindow = QtGui.QMainWindow()
menubar = QtGui.QMenuBar(MainWindow)
menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
menubar.setObjectName("menubar")

menuFile = QtGui.QMenu(menubar)
menuFile.setObjectName("menuFile")
MainWindow.setMenuBar(menubar)

actionupdateall = QtGui.QAction(MainWindow)
actionupdateall.setObjectName("actionupdateall")
actionupdateall.setText("Whee")

menuFile.addSeparator()
menuFile.addAction(actionupdateall)
menubar.addAction(menuFile.menuAction())

menuFile.setTitle(QtGui.QApplication.translate("MainWindow", "File", None, QtGui.QApplication.UnicodeUTF8))

MainWindow.show()

sys.exit(appt.exec_())

Worksforme (interesting, seems PR1.1(.1?) changed the menu behaviour, I get "File / Whee" on Qt4.5 and "Whee" on Qt4.6).

noobmonkey 2010-03-31 10:27

Re: pyqt Menu's - need an example please?
 
In the interest of letting everyone know how stupid i am.........


I was calling a menubar elsewhere in my code.... thus overwriting the menu i was trying to create....
(Massive thanks to everyone in here, + w00t on irc who actually went through my code and found it!!)


All times are GMT. The time now is 11:52.

vBulletin® Version 3.8.8