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

  • Home
  • SEARCH
  • 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 7516587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:10:44+00:00 2026-05-30T01:10:44+00:00

I am using Pyqt however c++ code is fine. I am trying to change

  • 0

I am using Pyqt however c++ code is fine. I am trying to change a menu item in QSystemTrayIcon using the QT framework in Linux (Ubuntu 11.10). Currently I have tried to reset the QMenu that I initially set:

self.tray = QSystemTrayIcon()
m = QMenu()
m.addAction('First')
m.addAction('Second')
tray.setContextMenu(m)

I place this in my class and make tray a class variable. I was thinking that if I just change the tray to set a new menu it would update:

new_m = QMenu()
new_m.addAction('First')
new_m.addAction('Third')
self.tray.setContextMenu(new_m)

However that doesn’t work and the tray menu is still the same as it was initially made. How could I be able to rebuild the menu to change it?

  • 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-30T01:10:46+00:00Added an answer on May 30, 2026 at 1:10 am

    I tested with the following code and it seems to work fine :

    from PyQt4.QtGui import *
    import sys
    
    class MainWindow(QMainWindow):
      def __init__(self):
        super(MainWindow, self).__init__()
    
        self.tray = QSystemTrayIcon(QApplication.style().standardIcon(QStyle.SP_DriveDVDIcon), self)
        m = QMenu()
        m.addAction('First')
        m.addAction('Second')
        self.tray.setContextMenu(m)
        self.tray.show()
    
        p = QPushButton("test", self)
        self.setCentralWidget(p)
        p.clicked.connect(self.onClick)
    
      def onClick(self):
        new_m = QMenu()
        new_m.addAction('First')
        new_m.addAction('Third')
        self.tray.setContextMenu(new_m)
    
    app = QApplication(sys.argv)
    w = MainWindow()
    w.show();
    sys.exit(app.exec_())
    

    Are you sure there is only one QSystemTrayIcon object ? (In your snippets, there is both self.tray and tray).

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

Sidebar

Related Questions

I am currently using the following PyQt code to create a simple browser: import
We currently have a fully functional Gui written created using PyQt. My partner wrote
I'm trying to display a QLabel (without parent) at a fixed position using PyQt.
I'm using PyQt and trying to promote a widget in QtDesigner. I'm able to
I am using PyQt and want to create a menu based on a list
I have a problem with keeping a GUI responsive using PyQt and Qthreads. What
i am using pyqt and designer . i have translated all the strings in
What I have done so far, using PyQt classes: all_Addresses = QNetworkInterface.allAddresses() #list-of-QHostAddress for
I'm writing a program using PyQt and I'm trying to figure out a way
I'm developing a qtwebkit based editor on linux using pyqt. I would like to

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.