A simple question how can I disable the auto-selection of a qmenubar.
what I want to deactivate is the option that when clicking on a Qmenu the click action remains when passing to the other buttons
That effect is thrown by the event QEvent::MouseMove
in the QMenuBar, if you want to discard it you have 2 possible solutions: the first is to create a class that inherits QMenuBar and overwrite the mouseMoveEvent()
method eliminating that task, and promote it so that it use Qt Designer, another simpler solution is to use an event filter, and that's what I'm going to show.
Assuming the code of your previous question that I answered Then the solution is the following:
class Principal(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
uic.loadUi("nuev.ui",self)
self.menuBar().installEventFilter(self)
def eventFilter(self, obj, event):
if obj is self.menuBar() and event.type() == QEvent.MouseMove:
return True
return QMainWindow.eventFilter(self, obj, event)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
p = Principal()
p.show()
sys.exit(app.exec_())
We return True
since we want that event not to be handled by the QMenuBar, if we restart False we tell it to handle it.