上傳檔案到「pyqt5/CODE/元件使用範例」
This commit is contained in:
parent
77d16b0368
commit
df4456c01d
40
pyqt5/CODE/元件使用範例/qt05_QDockWidget.py
Normal file
40
pyqt5/CODE/元件使用範例/qt05_QDockWidget.py
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
'''
|
||||||
|
【簡介】
|
||||||
|
PyQT5中QDockWidget範例
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from PyQt5.QtCore import *
|
||||||
|
from PyQt5.QtGui import *
|
||||||
|
from PyQt5.QtWidgets import *
|
||||||
|
|
||||||
|
class DockDemo(QMainWindow):
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super(DockDemo, self).__init__(parent)
|
||||||
|
layout = QHBoxLayout()
|
||||||
|
bar=self.menuBar()
|
||||||
|
file=bar.addMenu("File")
|
||||||
|
file.addAction("New")
|
||||||
|
file.addAction("Save")
|
||||||
|
file.addAction("Quit")
|
||||||
|
self.items = QDockWidget("Dockable", self)
|
||||||
|
self.listWidget = QListWidget()
|
||||||
|
self.listWidget.addItem("item1")
|
||||||
|
self.listWidget.addItem("item2")
|
||||||
|
self.listWidget.addItem("item3")
|
||||||
|
self.items.setWidget(self.listWidget)
|
||||||
|
self.items.setFloating(False)
|
||||||
|
self.setCentralWidget(QTextEdit())
|
||||||
|
self.addDockWidget(Qt.RightDockWidgetArea, self.items)
|
||||||
|
self.setLayout(layout)
|
||||||
|
self.setWindowTitle("Dock範例")
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
demo = DockDemo()
|
||||||
|
demo.show()
|
||||||
|
sys.exit(app.exec_())
|
30
pyqt5/CODE/元件使用範例/qt05_QListWidget.py
Normal file
30
pyqt5/CODE/元件使用範例/qt05_QListWidget.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
'''
|
||||||
|
【簡介】
|
||||||
|
PyQT5中QListWidget範例
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from PyQt5.QtCore import *
|
||||||
|
from PyQt5.QtGui import *
|
||||||
|
from PyQt5.QtWidgets import *
|
||||||
|
|
||||||
|
class ListWidget(QListWidget):
|
||||||
|
def clicked(self,item):
|
||||||
|
QMessageBox.information(self, "ListWidget", "您選擇了:"+item.text())
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
listWidget = ListWidget()
|
||||||
|
listWidget.resize(300,120)
|
||||||
|
listWidget.addItem("Item 1");
|
||||||
|
listWidget.addItem("Item 2");
|
||||||
|
listWidget.addItem("Item 3");
|
||||||
|
listWidget.addItem("Item 4");
|
||||||
|
listWidget.setWindowTitle('QListwidget範例')
|
||||||
|
listWidget.itemClicked.connect(listWidget.clicked)
|
||||||
|
listWidget.show()
|
||||||
|
sys.exit(app.exec_())
|
49
pyqt5/CODE/元件使用範例/qt05_QMultipleDoc.py
Normal file
49
pyqt5/CODE/元件使用範例/qt05_QMultipleDoc.py
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
'''
|
||||||
|
【簡介】
|
||||||
|
PyQT5中QMdiArea範例
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from PyQt5.QtCore import *
|
||||||
|
from PyQt5.QtGui import *
|
||||||
|
from PyQt5.QtWidgets 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):
|
||||||
|
print( "triggered")
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
demo = MainWindow()
|
||||||
|
demo.show()
|
||||||
|
sys.exit(app.exec_())
|
||||||
|
|
52
pyqt5/CODE/元件使用範例/qt05_QScrollBar.py
Normal file
52
pyqt5/CODE/元件使用範例/qt05_QScrollBar.py
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
'''
|
||||||
|
【簡介】
|
||||||
|
PyQT5中QScrollBar範例
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from PyQt5.QtCore import *
|
||||||
|
from PyQt5.QtGui import *
|
||||||
|
from PyQt5.QtWidgets import *
|
||||||
|
|
||||||
|
class Example(QWidget):
|
||||||
|
def __init__(self):
|
||||||
|
super(Example, self).__init__()
|
||||||
|
self.initUI()
|
||||||
|
|
||||||
|
def initUI(self):
|
||||||
|
hbox = QHBoxLayout( )
|
||||||
|
self.l1 = QLabel("拖動滑塊改變顏色")
|
||||||
|
self.l1.setFont(QFont("Arial",16))
|
||||||
|
hbox.addWidget(self.l1)
|
||||||
|
self.s1 = QScrollBar()
|
||||||
|
self.s1.setMaximum(255)
|
||||||
|
self.s1.sliderMoved.connect(self.sliderval)
|
||||||
|
self.s2 = QScrollBar()
|
||||||
|
self.s2.setMaximum(255)
|
||||||
|
self.s2.sliderMoved.connect(self.sliderval)
|
||||||
|
self.s3 = QScrollBar()
|
||||||
|
self.s3.setMaximum(255)
|
||||||
|
self.s3.sliderMoved.connect(self.sliderval)
|
||||||
|
hbox.addWidget(self.s1)
|
||||||
|
hbox.addWidget(self.s2)
|
||||||
|
hbox.addWidget(self.s3)
|
||||||
|
self.setGeometry(300, 300, 300, 200)
|
||||||
|
self.setWindowTitle('QScrollBar範例')
|
||||||
|
self.setLayout( hbox )
|
||||||
|
|
||||||
|
def sliderval(self):
|
||||||
|
print( self.s1.value(),self.s2.value(), self.s3.value() )
|
||||||
|
palette = QPalette()
|
||||||
|
c = QColor(self.s1.value(),self.s2.value(), self.s3.value(),255)
|
||||||
|
palette.setColor(QPalette.Foreground,c)
|
||||||
|
self.l1.setPalette(palette)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
demo = Example()
|
||||||
|
demo.show()
|
||||||
|
sys.exit(app.exec_())
|
37
pyqt5/CODE/元件使用範例/qt05_freshUi.py
Normal file
37
pyqt5/CODE/元件使用範例/qt05_freshUi.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
'''
|
||||||
|
【簡介】
|
||||||
|
PyQT5中即時刷新介面範例
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
from PyQt5.QtWidgets import QWidget, QPushButton , QApplication ,QListWidget, QGridLayout
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
class WinForm(QWidget):
|
||||||
|
|
||||||
|
def __init__(self,parent=None):
|
||||||
|
super(WinForm,self).__init__(parent)
|
||||||
|
self.setWindowTitle("即時刷新介面範例")
|
||||||
|
self.listFile= QListWidget()
|
||||||
|
self.btnStart = QPushButton('開始')
|
||||||
|
layout = QGridLayout(self)
|
||||||
|
layout.addWidget(self.listFile,0,0,1,2)
|
||||||
|
layout.addWidget(self.btnStart,1,1)
|
||||||
|
self.btnStart.clicked.connect( self.slotAdd)
|
||||||
|
self.setLayout(layout)
|
||||||
|
|
||||||
|
def slotAdd(self):
|
||||||
|
for n in range(10):
|
||||||
|
str_n='File index {0}'.format(n)
|
||||||
|
self.listFile.addItem(str_n)
|
||||||
|
QApplication.processEvents()
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
form = WinForm()
|
||||||
|
form.show()
|
||||||
|
sys.exit(app.exec_())
|
Loading…
Reference in New Issue
Block a user