Drag n Drop Button and Drop-down menu PyQt/Qt designer

前端 未结 4 2053
悲&欢浪女
悲&欢浪女 2020-12-11 11:27

I would like to know the \"best practice\" to change the behavior of some buttons to do the following:

I want with a click to appear a menu. Or when you drag this sa

4条回答
  •  萌比男神i
    2020-12-11 12:00

    If you want to draw a line between the buttons, it means you need to reimplement the "paintEvent" of the background widget (Possibly the parent widget of all subwidgets), as you said, this is NOT the best practice to do so. Instead, you need to use QGraphicsWidget, for drawing line, you need to use QGraphicsLineItem. It have the following member functions:

    setAcceptDrops
    dragEnterEvent ( QGraphicsSceneDragDropEvent * )
    dragLeaveEvent ( QGraphicsSceneDragDropEvent * )
    dragMoveEvent ( QGraphicsSceneDragDropEvent * )
    

    In the PyQt4 installation folder, there should exist a folder naming examples\graphicsview\diagramscene, which you take it for a reference.

提交回复
热议问题