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. QMenu on QPushbutton sometimes doesn't attach? [PySide/Python 3]
Forum Updated to NodeBB v4.3 + New Features

QMenu on QPushbutton sometimes doesn't attach? [PySide/Python 3]

Scheduled Pinned Locked Moved Language Bindings
1 Posts 1 Posters 997 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.
  • A Offline
    A Offline
    Alabaster
    wrote on last edited by
    #1

    I have several dynamically-generated buttons, each with their own attached QMenu. When I run my script, sometimes the QMenu attaches to all of the buttons, and sometimes it only attaches to a (seemingly random) number of buttons (leaving the other buttons menu-less). I can't detect a pattern to which ones "work" and which don't work each time I run the script, but the last few buttons are almost always correct.

    All of the QMenus and buttons are generated dynamically in a for loop, so I don't have any idea why some buttons would "work" and others wouldn't (or why the results would be different each time I run the script..).

    Each button has its own instance of the QMenu, but they are all identical. The QMenu's action texts are generated from a QSLQuery Model.

    I'll paste some relevant sample code below. I can't fit the whole script, but here is a description of some of the classes I haven't not included.

    class EntryRow(QWidget) -- includes a person's name (label), and several widgets to change that person's data, all arranged in an HBox layout. Each EntryRow's HBox is placed into its own grid location in the central widget.

    EACH ENTRY ROW INCLUDES A "self.commentsButton," which is a QPushButton with an attached QMenu.

    class CommentMenu(QMenu) -- each person's "commentsButton" has its own instance of the QMenu

    Here is how each menu is instantiated:
    @

    THIS OCCURS WITHIN METHOD "createWidgets" of the class EntryRow

        self.commentsButton = QPushButton("Com.")
        self.commentsButton.setFixedWidth(45)
        self.commentsButton.setCheckable(True)
        
        q = self.page.partCommentModel
    
        self.menu = CommentMenu(q, self, self.page)
        self.commentsButton.setMenu(self.menu)
    

    @

    @
    class CommentMenu(QMenu):
    def init(self, model, entryRow, page):
    super().init()
    self.actionList = []

        model.query().first()
        while model.query().next():
            text = model.query().record().value(0)
            #print("Value is {0}".format(text))
            newAction = QAction(entryRow)
            newAction.setText(text)
            newAction.setCheckable(True)
            self.actionList.append(newAction)
            self.addAction(newAction)@
    

    Any help would be appreciated. Let me know if there's any other relevant code you need me to post.

    Thanks

    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