将子窗口最小化为pyqt中的选项卡

时间:2016-07-12 22:25:05

标签: python tabs pyqt widget qtabwidget

我对PyQT很新,目前正在研究如何在mdi区域实现子窗口。我想知道在PyQT中是否可以最小化子窗口,以便在子窗口最小化后隐藏关闭/扩展/最小化按钮。默认情况下,以这种方式最小化子窗口组:

Example

我想要实现的基本上没有可见的按钮,只有子窗口的标题 - 双击标题会扩展子窗口。

 import sys
 from PyQt4 import QtGui, QtCore
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *

 class MainWindow(QMainWindow):
     count = 0

     def __init__(self, parent=None):
         super(MainWindow, self).__init__(parent)
         self.mdi = QMdiArea()
         self.setCentralWidget(self.mdi)
         bar = self.menuBar()

         file = bar.addMenu("File")
         file.addAction("New")
         file.addAction("Cascade")
         file.addAction("Tiled")
         file.triggered[QAction].connect(self.windowAction)
         self.setWindowTitle("MDI demo")

      def windowAction(self, q):

         if q.text() == "New":
             MainWindow.count = MainWindow.count + 1
             sub = QMdiSubWindow()
             sub.setWidget(QTextEdit())
             sub.setWindowTitle("subwindow" + str(MainWindow.count))
             self.mdi.addSubWindow(sub)
             sub.show()

         if q.text() == "cascade":
             self.mdi.cascadeSubWindows()

         if q.text() == "Tiled":
             self.mdi.tileSubWindows()

      def main():
          app = QApplication(sys.argv)
          ex = MainWindow()
          ex.show()
          sys.exit(app.exec_())

 if __name__ == '__main__':
     main()

0 个答案:

没有答案