Pyqt6 disgner QTableWidget/QTableView
pyside6(2):QMainWindow
PyQt5系列教程(52):QDockWidget的使用
class MyWidget(QMainWindow):
def __init__(self):
super().__init__()
hlayout = QHBoxLayout()
self.dock = QDockWidget("我是一个按钮", self)
self.bt = QPushButton("点我")
self.dock.setWidget(self.bt)
self.tt = QTextEdit()
self.setCentralWidget(self.tt)
self.addDockWidget(Qt.RightDockWidgetArea, self.dock)
self.setLayout(hlayout)
self.setWindowTitle("学点编程吧:代码如何使用QDockWidget")
self.bt.clicked.connect(self.game)
def game(self):
self.tt.append("你点我啦!")
if __name__ == "__main__":
app = QtWidgets.QApplication([])
widget = MyWidget()
widget.resize(800, 600)
widget.show()
sys.exit(app.exec())
PySide6/PyQT 可以实现多线程的多个类,有 QObject、QThread、QRunnable、QThreadPool 等
https://wenku.csdn.net/answer/66ff83dbf13541c58629fe88c2b6620a
import time
import threading
from PySide6.QtCore import QObject, Signal, Slot, QThread
from tqdm import tqdm
class Worker(QObject):
finished = Signal()
@Slot()
def do_work(self):
for i in tqdm(range(10)):
time.sleep(1)
self.finished.emit()
class MainWindow(QObject):
def __init__(self):
super().__init__()
self.thread = QThread()
self.worker = Worker()
self.worker.moveToThread(self.thread)
self.worker.finished.connect(self.thread.quit)
self.thread.started.connect(self.worker.do_work)
def start(self):
self.thread.start()
if __name__ == "__main__":
import sys
from PySide6.QtWidgets import QApplication
app = QApplication(sys.argv)
main_window = MainWindow()
main_window.start()
sys.exit(app.exec())
【Pyside6】Python多线程实现的选择与QThread的推荐实现方式
Python 把任意系统的路径转换成当前系统的格式(关于 / \ 分隔符的)
PySide 显示控制台print功能
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
from PySide6 import QtCore, QtGui
import sys
from PySide6.QtCore import QEventLoop, QTimer
from PySide6.QtWidgets import QApplication, QMainWindow
from Ui_ControlBoard import Ui_MainWindow
class EmittingStr(QtCore.QObject):
textWritten = QtCore.Signal(str)
def write(self, text):
self.textWritten.emit(str(text))
loop = QEventLoop()
QTimer.singleShot(100, loop.quit)
loop.exec_()
QApplication.processEvents()
class ControlBoard(QMainWindow, Ui_MainWindow):
def __init__(self):
super(ControlBoard, self).__init__()
self.setupUi(self)
# 下面将输出重定向到textBrowser中
sys.stdout = EmittingStr()
sys.stdout.textWritten.connect(self.outputWritten)
self.pushButton.clicked.connect(self.bClicked)
def outputWritten(self, text):
cursor = self.textBrowser.textCursor()
cursor.movePosition(QtGui.QTextCursor.End)
cursor.insertText(text)
self.textBrowser.setTextCursor(cursor)
self.textBrowser.ensureCursorVisible()
def bClicked(self):
"""Runs the main function."""
print('Begin')
self.printABCD()
print("End")
def printABCD(self):
print("aaaaaaaaaaaaaaaa")
print("bbbbbbbbbbbbbbbb")
print("cccccccccccccccc")
print("dddddddddddddddd")
if __name__ == "__main__":
app = QApplication(sys.argv)
win = ControlBoard()
win.show()
sys.exit(app.exec_())