简体   繁体   中英

How to disable right-click in PyQt5 and widget issue

I have a simple code that is making a window with toolbars.

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import sys

class AnaPencere(QMainWindow):
    def __init__(self):
        super().__init__()
        self.widget = QWidget(self)
        self.setCentralWidget(self.widget)

        self.toolBar = QToolBar(self)
        self.addToolBar(Qt.TopToolBarArea, self.toolBar)

        self.pushButton1 = QPushButton()
        self.pushButton1.setText("Open")
        self.toolBar.addWidget(self.pushButton1)

        self.toolBar.addSeparator()
        self.pushButton2 = QPushButton()
        self.pushButton2.setText("Save")
        self.toolBar.addWidget(self.pushButton2)

        self.pushButton3 = QPushButton()
        self.pushButton3.setText("Save as")
        self.toolBar.addWidget(self.pushButton3)
        #t = QToolBar(self)
        #t.setMovable(False)

uygulama = QApplication(sys.argv)
pencere = AnaPencere()
pencere.show()
uygulama.exec_()

This will create 3 toolbars. But the problem is, when I right click on a toolbar, a little window pops up, and when I click that little window all toolbars are gone. If I do the same thing again toolbars are back again. I don't want to user is able to do something like that so I thought If I disable right click it'll fixed but I couldn't. Here that little window

在此处输入图片说明

self.toolBar = QToolBar(self)  
self.addToolBar(Qt.TopToolBarArea, self.toolBar)  
self.toolBar.setContextMenuPolicy(Qt.PreventContextMenu)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM