Make toolbar when zooming in with cursor

I want to create a toolbar that doesn't appear until the cursor is close to the position of the toolbar.

Something like vlc for example, when in full screen, the toolbar below disappears after a while if it is inactive and when you approach it with your cursor it appears.

Can I do it with PyQt or PySide, i.e. to make the toolbar invisible until the cursor is at the top of my window?

+3


source to share


1 answer


Very interesting!

Yes, you can. The keyword keeps track of the mouse all the time as it moves. In pyqt use QWidget.mouseMoveEvent (self, QMouseEvent)

, but this method only tracks when the mouse is pressed, so you need to enable all movement using QWidget.setMouseTracking (self, bool enable)

it.

OK, see my example code at QWidget

, can also be implemented QMainWindow

(the other has QMainWindow

already QMenuBar

), hopefully this is a help;

import sys
from PyQt4 import QtGui

class QTestWidget (QtGui.QWidget):
    def __init__ (self):
        super(QTestWidget, self).__init__()
        self.myQMenuBar = QtGui.QMenuBar(self)
        exitMenu = self.myQMenuBar.addMenu('File')
        exitAction = QtGui.QAction('Exit', self)        
        exitAction.triggered.connect(QtGui.qApp.quit)
        exitMenu.addAction(exitAction)
        self.myQMenuBar.hide()
        self.setMouseTracking(True)

    def mouseMoveEvent (self, eventQMouseEvent):
        self.myQMenuBar.setVisible(True if eventQMouseEvent.y() <= 23 else False)
        QtGui.QWidget.mouseMoveEvent(self, eventQMouseEvent)

myQApplication = QtGui.QApplication(sys.argv)
myQTestWidget = QTestWidget()
myQTestWidget.show()
myQApplication.exec_()

      




QWidget.mouseMoveEvent (self, QMouseEvent)

Link
: http://pyqt.sourceforge.net/Docs/PyQt4/qwidget.html#mouseMoveEvent

QWidget.setMouseTracking (self, bool enable)

Link
: http://pyqt.sourceforge.net/Docs/PyQt4/qwidget.html#setMouseTracking




Hello,

+4


source







All Articles