Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. [Solved] Python/Pyqt - QtCore.Qt.RightButton not responding

[Solved] Python/Pyqt - QtCore.Qt.RightButton not responding

Scheduled Pinned Locked Moved Language Bindings
4 Posts 2 Posters 7.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    needhelp_gh
    wrote on last edited by
    #1

    Hi,

    I'm trying to create a right-click menu.

    All QShortCuts with keyboard buttons work, but not mouse-click QShortcuts...Here is my code:

    @shortcut = QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.RightButton), parent)
    // popupMenu func code
    widget.connect(shortcut, QtCore.SIGNAL("activated()"), popupMenu)@

    Is there anything I'm missing?

    Thanks!!


    http://abstrusegoose.com/432

    1 Reply Last reply
    0
    • N Offline
      N Offline
      needhelp_gh
      wrote on last edited by
      #2

      Any ideas?

      Thanks in advanced!!


      http://abstrusegoose.com/432

      1 Reply Last reply
      0
      • jazzycamelJ Offline
        jazzycamelJ Offline
        jazzycamel
        wrote on last edited by
        #3

        Hi,

        I'm not sure that you can use QShortcut in this way. However, QWidget has a built in approach to capturing right mouse clicks and rendering context menus as the following example shows:

        @
        from PyQt4.QtCore import *
        from PyQt4.QtGui import *

        class Widget(QWidget):
        def init(self, parent=None):
        QWidget.init(self, parent)

            self.setContextMenuPolicy(Qt.CustomContextMenu)
            self.customContextMenuRequested.connect(self.showMenu)
        
        def showMenu(self, pos):
            menu=QMenu(self)
            menu.addAction(QAction("Item 1", menu))
            menu.addAction(QAction("Item 2", menu))
            menu.addAction(QAction("Item 3", menu))
            menu.popup(self.mapToGlobal(pos))
        

        if name=="main":
        from sys import argv, exit
        a=QApplication(argv)
        w=Widget()
        w.show()
        exit(a.exec_())
        @

        Hope this helps ;o)

        For the avoidance of doubt:

        1. All my code samples (C++ or Python) are tested before posting
        2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
        1 Reply Last reply
        0
        • N Offline
          N Offline
          needhelp_gh
          wrote on last edited by
          #4

          Thanks so much, jazzycamel! :)

          That worked great!!!


          http://abstrusegoose.com/432

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved