自己做个好用的pysdie 2 cheat sheet

在很多地方都流行可以随时查找的cheatsheet,那PySide2 有吗? 笔者不清楚,乾脆直接做一个好了 ....

INSTALL

  • pip3 install PySide2

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_()

<<:  [26] 用 python 刷 Leetcode: 150 evaluate reverse polish notatio

>>:  D3JsDay25圈圈圆圆圈圈,甜甜黏黏甜甜—圆饼图与环圈图

更新网格机器人和策略回测

Strategies: 交易成本的正负号写反了,最近用一小时线测试才发现这件事 把交易成本设定移到前...

认识HTML(四):加入图片

在HTML文件中加入图片,可以在想置入图片的地方使用img标签。 <img>是单一元素,它不用开头和...

如何清除 iMac/Macbook 上所有资料?--〖2022亲测有用〗

如何完成Mac的所有信息? 分享阅读本文,恢复最完整的Mac和明确的教学,我们将使用专业的Mac清洁...

FortiGate 60E 设置虚拟服务器

步骤 连上防火墙设置 建立虚拟服务器 开放防火墙 连上防火墙设置 在浏览器输入192.168.1.9...

Ruby 最佳实践

概述 Ruby 程序语言的安全性原则,主要聚焦於 Ruby on Rails Web 框架。 注意事...