使用pyqt4 python创建垂直手风琴下拉菜单

时间:2018-10-17 09:31:54

标签: python pyqt pyqt4 accordion

this文档中,我知道只能将LayoutDirection设置为LeftToRight或RightToLeft。但是,我希望布局方向向下,类似于ComboBox中的ComboBox。

这是我的代码。

#!/usr/bin/python
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui  import *

class menudemo(QMainWindow):
   def __init__(self, parent = None):
      super(menudemo, self).__init__(parent)

      layout = QHBoxLayout()
      bar = self.menuBar()
      FILE = bar.addMenu("File")
      FILE.menuAction().setVisible(False)
      clone = FILE.addMenu("Clone")
      FILE.addAction("Commit")
      FILE.addAction("Push")
      FILE.addAction("Pull")

      lteue = clone.addMenu("lteue")
      lteue_branches = lteue.addMenu("Existing Branches")

      for i in range(10):
        branch = "Branch-" + str(i+1)
        lteue_branches.addAction(branch)

      b1 = QPushButton(self)
      b1.setText("Operations")
      b1.resize(120, 40)
      b1.move(50,50)
      b1.setMenu(FILE)

      self.setLayout(layout)
      self.setWindowTitle("menu demo")

def main():
   app = QApplication(sys.argv)
   ex = menudemo()
   ex.setGeometry(200,200,200,200)
   ex.show()
   sys.exit(app.exec_())

if __name__ == '__main__':
   main()

我需要的内容显示在屏幕截图中

screenshot-1

screenshot-2

screenshot-3

0 个答案:

没有答案