为什么我撕掉菜单后QMenu动作消失了?
之前:
之后:
import os, sys
from PySide import QtGui, QtCore
class QFilterButton(QtGui.QPushButton):
def __init__(self, *args, **kwargs):
super(QFilterButton, self).__init__(*args, **kwargs)
# controls
self.ui_search = QtGui.QLineEdit()
self.ui_search.setPlaceholderText('Search...')
self.ui_list = QtGui.QListView()
self.ui_clear = QtGui.QPushButton('Clear')
# lay main
lay_main = QtGui.QVBoxLayout()
lay_main.addWidget(self.ui_search)
lay_main.addWidget(self.ui_list)
lay_main.addWidget(self.ui_clear)
widget = QtGui.QWidget()
widget.setLayout(lay_main)
# create flyout menu
act_widget = QtGui.QWidgetAction(self)
act_widget.setDefaultWidget(widget)
self.menu = QtGui.QMenu(self)
self.menu.setTearOffEnabled(True)
self.menu.setWindowTitle('Filters')
self.menu.addAction(act_widget)
self.setMenu(self.menu)
self.setText('Status (12)')
app = QtGui.QApplication(sys.argv)
lay = QtGui.QVBoxLayout()
lay.addWidget(QFilterButton())
ex = QtGui.QWidget()
ex.setLayout(lay)
ex.show()
sys.exit(app.exec_())