首页 PyQt5教程 QCommandLinkButton命令链接按钮控件API和信号
pay pay
教程目录

QCommandLinkButton命令链接按钮控件API和信号

日期: 四月 25, 2023, 8:43 a.m.
栏目: PyQt5教程
阅读: 172
作者: Python自学网-村长

摘要: QCommandLinkButton是QPushButton的一个子类,它提供了一个带有说明文字和详细说明的按钮。通常用于一些重要的操作,以便用户明确知道这个按钮的功能。

QCommandLinkButton是QPushButton的一个子类,它提供了一个带有说明文字和详细说明的按钮。通常用于一些重要的操作,以便用户明确知道这个按钮的功能。

在使用QCommandLinkButton时,可以设置按钮的文字和详细说明,也可以设置按钮的图标。同时,QCommandLinkButton也继承了QPushButton的所有API和信号。

下面是一个简单的例子,展示如何使用QCommandLinkButton:

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QCommandLinkButton


class MyWidget(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('QCommandLinkButton Demo')
        self.setGeometry(100, 100, 300, 200)

        vbox = QVBoxLayout()

        btn1 = QCommandLinkButton('Open', 'Open a file', self)
        btn1.setIcon(self.style().standardIcon(1))
        btn1.clicked.connect(self.on_btn1_clicked)
        vbox.addWidget(btn1)

        btn2 = QCommandLinkButton('Save', 'Save the file', self)
        btn2.setIcon(self.style().standardIcon(2))
        btn2.clicked.connect(self.on_btn2_clicked)
        vbox.addWidget(btn2)

        self.setLayout(vbox)

    def on_btn1_clicked(self):
        print('Open button clicked')

    def on_btn2_clicked(self):
        print('Save button clicked')


if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = MyWidget()
    w.show()
    sys.exit(app.exec_())

运行这个程序,可以看到两个QCommandLinkButton,每个按钮都带有一个说明和一个详细说明。点击按钮会输出相应的信息。

部分文字内容为【Python自学网】原创作品,转载请注明出处!视频内容已申请版权,切勿转载!
回顶部