D
D
Daniil Chashkov2018-06-14 16:10:16
Python
Daniil Chashkov, 2018-06-14 16:10:16

How to implement a pull down menu?

Similar to this -
5b2269262c61a016532307.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-06-15
@imnotwhoexpect

This is how you can start, further develop yourself

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


class PopupMenu(QWidget):
    
    def __init__(self):
        super().__init__()
        self.setWindowTitle('Пример всплывающего меню')
        self.resize(300, 300)
        
        self.label = QLabel(self)
        self.label.setText("МЕНЮ")

        self.popup_menu = QLabel(self)
        self.popup_menu.resize(180, 100)
        self.popup_menu.setText("Hello PyQt5!")
        self.popup_menu.setStyleSheet("border: 2px solid grey; font: 75 italic 16pt Verdana;\
                text-align: center; border-radius: 10px;\
                background-color: lightblue; width: 10px;")

        self.popup_menu.hide()

        hbox = QHBoxLayout()
        hbox.setAlignment(Qt.AlignCenter)
        hbox.addStretch(2)
        hbox.addWidget(self.label)
        hbox.addWidget(self.popup_menu)

        self.label.installEventFilter(self)

    def eventFilter(self, obj, event):
        # Если мышь над виджетом
        if event.type() == 10:
            self.popup_menu.show()
            
        # Если мышь покинула область виджета
        elif event.type() == 11:
            pass
        return False


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = PopupMenu()
    window.show()
    sys.exit(app.exec_())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question