首頁>技術>

QCommandLinkButton簡介

QCommandLinkButton部件是一個繼承於QPushButton的控制元件,擁有QPushButton所有的方法和訊號。它的用途類似於單選按鈕, 常應用於一組互斥選項間進行選擇,其外觀類似通常的平面按鈕,它除了有標題文字外,還允許設定一個描述文字,在預設情況下,它還會帶有一個向右的箭頭圖示,表示按下該控制元件將開啟另一個視窗或者頁面。

除了繼承自QPushButton的方法和訊號外,它還有常用函式:

setDescription(): 設定描述資訊description(): 獲得按鈕的描述資訊

QCommandLinkButton類繼承關係:

測試QCommandLinkButton

建立檔案qcommandlinkbutton.py在其中新增一個QCommandLinkButton按鈕, 設定文字和描述資訊,點選該按鈕,退出程式,完整程式碼如下:

import sysfrom PyQt5 import QtCore, QtGui, QtWidgetsfrom PyQt5.QtWidgets import (QApplication, QWidget, QCommandLinkButton, QVBoxLayout) class DemoCommandLinkButton(QWidget):    def __init__(self, parent=None):        super(DemoCommandLinkButton, self).__init__(parent)                       # 設定視窗標題        self.setWindowTitle('實戰PyQt5: QCommandLinkButton Demo!')              # 設定視窗大小        self.resize(400, 240)                clbtn = QCommandLinkButton(self)        clbtn.setText('退出')        clbtn.setDescription('點選本按鈕,退出應用')        clbtn.clicked.connect(self.onCommandLinkButtonClicked)                vLayout = QVBoxLayout(self)        vLayout.addStretch()        vLayout.addWidget(clbtn)        vLayout.addStretch()                self.setLayout(vLayout)            def onCommandLinkButtonClicked(self):        self.close()        if __name__ == '__main__':    app = QApplication(sys.argv)    window = DemoCommandLinkButton()    window.show()    sys.exit(app.exec())

執行結果如下圖:

本文知識點QCommandLinkButton的常用場景。

喜歡本文內容的就收藏,點贊,評論,關注和轉發。

53
最新評論
  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • Mac上通過docker配置PHP開發環境