答案 0 :(得分:1)
您可以通过设置QToolButton
来使用QMenu
:
from PyQt5 import QtGui, QtWidgets
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
button = QtWidgets.QToolButton(
icon=QtGui.QIcon("plus.png"),
popupMode=QtWidgets.QToolButton.InstantPopup
)
menu = QtWidgets.QMenu(button)
menu.addAction(QtGui.QIcon("insert.png"), "Insert multiple rows")
menu.addSeparator()
menu.addAction("Place new rows above selected row")
menu.addAction("Place new rows bellow selected row")
menu.addAction("Place new rows at the end of the data view")
button.setMenu(menu)
toolbar = self.addToolBar("tools")
toolbar.addWidget(button)
tableWidget = QtWidgets.QTableWidget(10, 10)
self.setCentralWidget(tableWidget)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.resize(640, 480)
w.show()
sys.exit(app.exec_())
答案 1 :(得分:0)
尝试调查QtGui.QComboBox
希望这就是您所需要的