设置按钮背景图
在qrc文件中导入背景图,目录为/qrc/a/b.png
ui.pushbutton.setStySheet("background-image:url(:/a/b.png);")
从uic文件中导入,并show
from uic import ui
app = QApplication(sys.argv)
window = Qwindow()
ui = ui()
ui.setupUi(window)
sys.exit(self.app.exec())
切换到其他窗口app和exit改变写法
app = QApplication.instance()
...
app.exec()
pyside6中多线程写法
class TimerThread(QThread):
finished = Signal()
count_signal = Signal()
def __init__(self, label):
super().__init__()
self.is_stopped = True
self.is_continue = True
self.is_close = True
self.is_stopped = False
self.is_continue = False
self.is_close = False
self.label = label
def run(self):
while True:
# 终止信号
if self.is_stopped:
return
# 如果暂停
if self.is_continue:
time.sleep(1)
continue
# 如果关闭窗口
if self.is_close:
return
#print('006')
current_time = time.strftime('%H:%M:%S')
if self.label.text() == '99:99:99':
self.label.setText(current_time)
a = current_time
#print(a)
if a != current_time:
self.label.setText(current_time)
a = current_time
#print(current_time)
#time.sleep(0.7)
# 窗口关闭方法
def on_close(self):
self.is_close = True
# 停止方法
def stop(self):
self.is_stopped = True
# 暂停方法
def pause(self):
self.is_continue = True
# 继续方法
def run_continue(self):
self.is_continue = False
window样式设定
#pyside6写法
#无边框
setWindowFlag(Qt.WindowType.FramelessWindowHint)
#置顶
setWindowFlag(Qt.WindowType.WindowStaysOnTopHint)
#背景透明
setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
lineEdit样式
border:2px groove gray;border-radius:10px;padding:2px 4px