Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6227071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:09:02+00:00 2026-05-24T09:09:02+00:00

im just a beginner in PyQT. and im not sure if my thread title

  • 0

im just a beginner in PyQT.
and im not sure if my thread title is the correct thing to put for my problem.

im having a problem creating a popmenu on a Qpushbutton.
based on the doc of QT docs

i need to make a QPushButton.setMenu (self, QMenu menu)

but i really dont know where to start.. i cant find a sample on how to use this.
please help me making one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:09:03+00:00Added an answer on May 24, 2026 at 9:09 am

    The basic idea is that you first have to create a QMenu, then use the setMenu method to attach it to your push button. If you look at the QMenu documentation, you’ll see that there is a method called addAction that will add menu items to your newly created QMenu. addAction is overloaded, so there are a lot of different ways to call it. You can use icons in your menu, specify keyboard shortcuts and other things. To keep things simple though, let’s just add a menu item and give it a method to call if that item is selected.

    from PyQt4 import QtGui, QtCore
    import sys
    
    
    class Main(QtGui.QMainWindow):
        def __init__(self, parent=None):
            super(Main, self).__init__(parent)
            pushbutton = QtGui.QPushButton('Popup Button')
            menu = QtGui.QMenu()
            menu.addAction('This is Action 1', self.Action1)
            menu.addAction('This is Action 2', self.Action2)
            pushbutton.setMenu(menu)
            self.setCentralWidget(pushbutton)
    
        def Action1(self):
            print 'You selected Action 1'
    
        def Action2(self):
            print 'You selected Action 2'
    
    
    if __name__ == '__main__':
    
        app = QtGui.QApplication(sys.argv)
        main = Main()
        main.show()
        app.exec_()
    

    Here we’ve created a push button (creatively named pushbutton). We then create a menu (again creatively named menu) using QtGui.QMenu(). The actions are created by calling addAction and giving it a string that will be used as the menu item text and a method (self.Action1 or self.Action2) that will be called if that menu item is selected. Then we call the setMenu method of pushbutton to assign our menu to it. When you run it and select an item, you should see text printed corresponding to the selected item.

    That’s the basic idea. You can look through the QMenu docs to get a better idea of the functionality of QMenu.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I am a C++ beginner just encountered a problem I don't know how
This may sound like a stupid question but I'm a beginner not just to
Complete programming beginner just trying to clarify something, I was creating keys for a
I'm just a beginner in Cocoa developing for Snow Leopard and I have problem
I am just a beginner in ASP.NET. My question is simple, I wanna add
I'm just a beginner with android. I want to divide a bitmap image into
Could someone please help me in here, I'm just a beginner who want to
I am just an Arduino beginner. I bought an Arduino Uno and a Wifly
I am just a new beginner in MySQL and I wanted to write the
Am a beginner in unix and I have just landed into a snag. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.