datetime:2019/5/23 13:37
author:nzb
可停靠的窗口小部件
from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication, QPushButton, QStackedWidget, QGroupBox, QComboBox, QDialog, QTabWidget, QWidget, QVBoxLayout, QLabel
from PyQt5.QtWidgets import QTextEdit, QDockWidget, QMainWindow, QListWidget
import sys
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import Qt
class DockDialog(QMainWindow):
"""可停靠的窗口小部件"""
def __init__(self):
super().__init__()
self.title = 'PyQt5 DockDialog'
self.left = 600
self.top = 200
self.width = 500
self.height = 400
self.iconName = '../img/home.ico'
self.initWindow()
def initWindow(self):
self.setWindowIcon(QtGui.QIcon(self.iconName))
self.setGeometry(self.left, self.top, self.width, self.height)
self.setWindowTitle(self.title)
self.createDockWidget()
self.show()
def createDockWidget(self):
menubar = self.menuBar()
file = menubar.addMenu("File")
file.addAction("New")
file.addAction("Save")
file.addAction("Close")
self.dock = QDockWidget("Dockable", self)
self.listwidget = QListWidget()
list1 = ['Python', 'C++', 'Java']
self.listwidget.addItems(list1)
self.dock.setWidget(self.listwidget)
self.setCentralWidget(QTextEdit())
self.addDockWidget(Qt.RightDockWidgetArea, self.dock)
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = DockDialog()
sys.exit(app.exec_())