Reply
Thread Tools
noobmonkey's Avatar
Posts: 3,203 | Thanked: 1,391 times | Joined on Nov 2009 @ Worthing, England
#1
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)
__________________
----------- Follow me on Twitter here
----------- My Photography Website and Blog is here
----------- Author of the N900 Health Check Application ----------- New Version in Extras Devel (Dec 2010 - 2.9.10)
----------- Are you on the N900 World Map? - http://pininthemap.com/maemo - masterpin: shotgun
----------- What apps do you want to see on the n900 or in MeeGo in the future? -
 
Posts: 3,319 | Thanked: 5,610 times | Joined on Aug 2008 @ Finland
#2
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)
__________________
Blogging about mobile linux - The Penguin Moves!
Maintainer of PyQt (see introduction and docs), AppWatch, QuickBrownFox, etc
 

The Following User Says Thank You to attila77 For This Useful Post:
krk969's Avatar
Posts: 754 | Thanked: 630 times | Joined on Sep 2009 @ London
#3
Originally Posted by noobmonkey View Post
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.
__________________
Developer of :
Buddy - budget/expense manager ( website )
Showtime - a telly channel listing viewer/reminder ( website )
Travelapp - london underground status/planner ( website )
Batlevel - desktop widget for battery level ( website )

“I hear and I forget. I see and I remember. I do and I understand.”
 

The Following User Says Thank You to krk969 For This Useful Post:
noobmonkey's Avatar
Posts: 3,203 | Thanked: 1,391 times | Joined on Nov 2009 @ Worthing, England
#4
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 :|
__________________
----------- Follow me on Twitter here
----------- My Photography Website and Blog is here
----------- Author of the N900 Health Check Application ----------- New Version in Extras Devel (Dec 2010 - 2.9.10)
----------- Are you on the N900 World Map? - http://pininthemap.com/maemo - masterpin: shotgun
----------- What apps do you want to see on the n900 or in MeeGo in the future? -
 
Posts: 3,319 | Thanked: 5,610 times | Joined on Aug 2008 @ Finland
#5
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).
__________________
Blogging about mobile linux - The Penguin Moves!
Maintainer of PyQt (see introduction and docs), AppWatch, QuickBrownFox, etc
 

The Following User Says Thank You to attila77 For This Useful Post:
noobmonkey's Avatar
Posts: 3,203 | Thanked: 1,391 times | Joined on Nov 2009 @ Worthing, England
#6
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!!)
__________________
----------- Follow me on Twitter here
----------- My Photography Website and Blog is here
----------- Author of the N900 Health Check Application ----------- New Version in Extras Devel (Dec 2010 - 2.9.10)
----------- Are you on the N900 World Map? - http://pininthemap.com/maemo - masterpin: shotgun
----------- What apps do you want to see on the n900 or in MeeGo in the future? -
 
Reply

Tags
menu, menubar, pyqt, qmenubar


 
Forum Jump


All times are GMT. The time now is 23:28.