上傳檔案到「pyqt5/CODE/元件使用範例」
This commit is contained in:
parent
68543f9046
commit
f72545ed0c
49
pyqt5/CODE/元件使用範例/qt04_QMultipleDoc.py
Normal file
49
pyqt5/CODE/元件使用範例/qt04_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_())
|
||||||
|
|
25
pyqt5/CODE/元件使用範例/qt04_QPixmap.py
Normal file
25
pyqt5/CODE/元件使用範例/qt04_QPixmap.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
'''
|
||||||
|
【簡介】
|
||||||
|
PyQt5中QPixmap範例
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from PyQt5.QtCore import *
|
||||||
|
from PyQt5.QtGui import *
|
||||||
|
from PyQt5.QtWidgets import *
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
win = QWidget()
|
||||||
|
lab1 = QLabel()
|
||||||
|
lab1.setPixmap(QPixmap("./images/python.jpg"))
|
||||||
|
vbox=QVBoxLayout()
|
||||||
|
vbox.addWidget(lab1)
|
||||||
|
win.setLayout(vbox)
|
||||||
|
win.setWindowTitle("QPixmap 範例")
|
||||||
|
win.show()
|
||||||
|
sys.exit(app.exec_())
|
52
pyqt5/CODE/元件使用範例/qt04_QScrollBar.py
Normal file
52
pyqt5/CODE/元件使用範例/qt04_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_())
|
46
pyqt5/CODE/元件使用範例/qt04_QSplitter.py
Normal file
46
pyqt5/CODE/元件使用範例/qt04_QSplitter.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
'''
|
||||||
|
【簡介】
|
||||||
|
PyQt5中QSplitter範例
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from PyQt5.QtCore import *
|
||||||
|
from PyQt5.QtGui import *
|
||||||
|
from PyQt5.QtWidgets import *
|
||||||
|
|
||||||
|
class SplitterExample(QWidget):
|
||||||
|
def __init__(self):
|
||||||
|
super(SplitterExample, self).__init__()
|
||||||
|
self.initUI()
|
||||||
|
|
||||||
|
def initUI(self):
|
||||||
|
hbox = QHBoxLayout(self)
|
||||||
|
self.setWindowTitle('QSplitter範例')
|
||||||
|
self.setGeometry(300, 300, 300, 200)
|
||||||
|
topleft = QFrame()
|
||||||
|
topleft.setFrameShape(QFrame.StyledPanel)
|
||||||
|
|
||||||
|
bottom = QFrame()
|
||||||
|
bottom.setFrameShape(QFrame.StyledPanel)
|
||||||
|
|
||||||
|
splitter1 = QSplitter(Qt.Horizontal)
|
||||||
|
textedit = QTextEdit()
|
||||||
|
splitter1.addWidget(topleft)
|
||||||
|
splitter1.addWidget(textedit)
|
||||||
|
splitter1.setSizes([100,200])
|
||||||
|
splitter2 = QSplitter(Qt.Vertical)
|
||||||
|
splitter2.addWidget(splitter1)
|
||||||
|
splitter2.addWidget(bottom)
|
||||||
|
hbox.addWidget(splitter2)
|
||||||
|
self.setLayout(hbox)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
demo = SplitterExample()
|
||||||
|
demo.show()
|
||||||
|
sys.exit(app.exec_())
|
||||||
|
|
70
pyqt5/CODE/元件使用範例/qt04_QStackedWidget.py
Normal file
70
pyqt5/CODE/元件使用範例/qt04_QStackedWidget.py
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
'''
|
||||||
|
【簡介】
|
||||||
|
PyQt5中QStackedWidget範例
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from PyQt5.QtCore import *
|
||||||
|
from PyQt5.QtGui import *
|
||||||
|
from PyQt5.QtWidgets import *
|
||||||
|
|
||||||
|
class StackedExample(QWidget):
|
||||||
|
def __init__(self):
|
||||||
|
super(StackedExample, self).__init__()
|
||||||
|
self.setGeometry(300, 50, 10,10)
|
||||||
|
self.setWindowTitle('StackedWidget範例')
|
||||||
|
|
||||||
|
self.leftlist = QListWidget ()
|
||||||
|
self.leftlist.insertItem (0, '聯絡方式' )
|
||||||
|
self.leftlist.insertItem (1, '個人資訊' )
|
||||||
|
self.leftlist.insertItem (2, '教育程度' )
|
||||||
|
self.stack1= QWidget()
|
||||||
|
self.stack2= QWidget()
|
||||||
|
self.stack3= QWidget()
|
||||||
|
self.stack1UI()
|
||||||
|
self.stack2UI()
|
||||||
|
self.stack3UI()
|
||||||
|
self.Stack = QStackedWidget (self)
|
||||||
|
self.Stack.addWidget (self.stack1)
|
||||||
|
self.Stack.addWidget (self.stack2)
|
||||||
|
self.Stack.addWidget (self.stack3)
|
||||||
|
hbox = QHBoxLayout(self)
|
||||||
|
hbox.addWidget(self.leftlist)
|
||||||
|
hbox.addWidget(self.Stack)
|
||||||
|
self.setLayout(hbox)
|
||||||
|
self.leftlist.currentRowChanged.connect(self.display)
|
||||||
|
|
||||||
|
def stack1UI(self):
|
||||||
|
layout=QFormLayout()
|
||||||
|
layout.addRow("姓名",QLineEdit())
|
||||||
|
layout.addRow("地址",QLineEdit())
|
||||||
|
self.stack1.setLayout(layout)
|
||||||
|
|
||||||
|
def stack2UI(self):
|
||||||
|
layout=QFormLayout()
|
||||||
|
sex=QHBoxLayout()
|
||||||
|
sex.addWidget(QRadioButton("男"))
|
||||||
|
sex.addWidget(QRadioButton("女"))
|
||||||
|
layout.addRow(QLabel("性別"),sex)
|
||||||
|
layout.addRow("生日",QLineEdit())
|
||||||
|
self.stack2.setLayout(layout)
|
||||||
|
|
||||||
|
def stack3UI(self):
|
||||||
|
layout=QHBoxLayout()
|
||||||
|
layout.addWidget(QLabel("科目"))
|
||||||
|
layout.addWidget(QCheckBox("物理"))
|
||||||
|
layout.addWidget(QCheckBox("數學"))
|
||||||
|
self.stack3.setLayout(layout)
|
||||||
|
|
||||||
|
def display(self,i):
|
||||||
|
self.Stack.setCurrentIndex(i)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
demo = StackedExample()
|
||||||
|
demo.show()
|
||||||
|
sys.exit(app.exec_())
|
Loading…
Reference in New Issue
Block a user