Python PyQt6 QWidgetAction, QFrame not showing in QPushButton menu

Viewed 22

I am trying to place a horizontal QFrame in a Qmenu attached to a QPushbutton, but it won't show. Calling actions() on the QMenu (in the MRE) returns 6 actions, yet the frames don't show up. Is this because frames can't be added to a menu? Here is the Meal Ready to Eat:

from PyQt6 import QtWidgets as W


class GUI(W.QMainWindow):
    def __init__(self):
        super().__init__()
        button = W.QPushButton('TEST')
        self.setCentralWidget(button)
        menu = W.QMenu()
        button.setMenu(menu)
        for e in range(3):
            label = W.QLabel(f'Placeholder {e}')
            widget = W.QWidgetAction(menu)
            widget.setDefaultWidget(label)
            menu.addAction(widget)
            frame = W.QFrame()
            frame.setFrameShape(W.QFrame.Shape.HLine)
            widget = W.QWidgetAction(menu)
            widget.setDefaultWidget(frame)
            menu.addAction(widget)


app = W.QApplication([])
main_gui = GUI()
main_gui.show()
app.exec()

I've tried setting a frame width, but still nothing shows. Above is the MRE that should, at the least, be spaced for a frame. Any ideas?

0 Answers
Related