在很多地方都流行可以隨時查找的cheatsheet,那PySide2 有嗎? 筆者不清楚,乾脆直接做一個好了 ....
INSTALL
Hello World
from PySide2.QtWidgets import *
app = QApplication([])
window = QWidget()
layout = QVBoxLayout()
button = QPushButton("Push Button")
layout.addWidget(QLabel('Hello World!'))
layout.addWidget(button)
window.setLayout(layout)
window.show()
app.exec_()
Widgets
from PySide2.QtCore import Qt
from PySide2.QtWidgets import *
app = QApplication([])
window = QWidget()
layout = QVBoxLayout()
slipper = QSlider(Qt.Horizontal)
button = QPushButton(“Push button")
layout.addWidget(QLabel('Hello World!'))
layout.addWidget(button)
layout.addWidget(slipper)
window.setLayout(layout)
window.show()
app.exec_()
Layout
from PySide2.QtWidgets import *
app = QApplication([])
window = QWidget()
layout = QHBoxLayout()
label = QLabel("O_o ....o_O")
button1 = QPushButton("One")
button2 = QPushButton("Two")
button3 = QPushButton("Three")
layout.addWidget(label)
layout.addWidget(button1)
layout.addWidget(button2)
layout.addWidget(button3)
window.setLayout(layout)
window.show()
app.exec_()
chart
from PySide2 import QtGui
from PySide2.QtWidgets import *
from PySide2.QtCharts import QtCharts
from PySide2.QtGui import QPainter
from random import randint
app = QApplication([])
window = QWidget()
layout = QVBoxLayout()
chart = QtCharts.QChart()
lineSeries = QtCharts.QLineSeries()
dt = [(i+1, randint(0, 99999)) for i in range(300)]
for point in dt:
ls.append(point[0],point[1])
chart.addSeries(ls)
chart.setTitle("RNS")
chart.createDefaultAxes()
cv = QtCharts.QChartView(chart)
cv.setRenderHint(QPainter.Antialiasing)
ls.setColor(QtGui.QColor("yellow"))
cv.chart().setBackgroundBrush(QtGui.QColor("green"))
layout.addWidget(cv)
window.setLayout(layout)
window.show()
window.resize(700, 500)
app.exec_()