Python PyQt6 QWidgetAction, QFrame not showing in QPushButton menu

Issue

This Content is from Stack Overflow. Question asked by malonn

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)


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?



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?