Python GUI编程网 > PyQt5控件_PyQt5控件方法大全 > PyQt5按钮控件QPushButton子类QCommandLinkButton学习
python教程

PyQt5按钮控件QPushButton子类QCommandLinkButton学习

发布博客:2022年11月17日 01:39
阅读:109
作者:Python GUI编程网

QCommandLinkButton是QPushButton的子类,信号完全继承这里就不演示了,主要看看QCommandLinkButton的方法和效果。

QCommandLinkButton是QPushButton的子类,信号完全继承这里就不演示了,主要看看QCommandLinkButton的方法和效果。首先看一下他的构造:

class QCommandLinkButton(QPushButton):
     """
     QCommandLinkButton(parent: QWidget = None)
     QCommandLinkButton(str, parent: QWidget = None)
     QCommandLinkButton(str, str, parent: QWidget = None)
     """

从构造可以看出来QCommandLinkButton和QPushButton几乎是一样的,唯一不一样的是里面可以传入2个字符串,具体有什么区别直接创建一个控件看看是什么效果就知道了。

QPushButton

可以看出来,第一个字符串相当于QPushButton中的setText文本,第二个可以作为描述文字,如果想单独设置使用方法setDescription()。下面是完整代码。

from PyQt5.Qt import *
 import sys
 
 app = QApplication(sys.argv)
 window = QWidget()
 window.setWindowTitle('QCommandLinkButton - PyQt5中文网')
 window.resize(600, 450)
 
 btn1 = QPushButton(window)
 btn1.move(80, 60)
 btn1.resize(80, 40)
 btn1.setText('按钮1')
 
 btn2 = QCommandLinkButton('按钮2', '这是一个链接按钮', window)
 # btn2.setDescription()
 btn2.move(80, 160)
 btn2.resize(150, 70)
 
 window.show()
 sys.exit(app.exec_())