PythonQt学习笔记

设置按钮背景图

在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

引用:qss简介大全-CSDN博客

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值