Open In App

PyQt5 – QCommandLinkButton Class

Improve
Improve
Like Article
Like
Save
Share
Report

QCommandLinkButton is a control widget that was introduced by Windows Vista. Its intended use is similar to that of a radio button in that it is used to choose between a set of mutually exclusive options. The appearance of it is generally similar to that of a flat push button, but it allows for a descriptive text in addition to the normal button text. By default it will also carry an arrow icon, indicating that pressing the control will open another window or page or do something. Below is how the command link button looks like

Example :
We will create a window having a label and the command link button and when the command link button pressed the counter will increment in the label

Below is the implementation




# importing libraries
from PyQt5.QtWidgets import * 
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import * 
from PyQt5.QtCore import * 
import sys
  
class Window(QMainWindow):
  
    def __init__(self):
        super().__init__()
  
        # setting title
        self.setWindowTitle("Python ")
  
        # setting geometry
        self.setGeometry(100, 100, 500, 400)
  
        # calling method
        self.UiComponents()
  
        # showing all the widgets
        self.show()
  
  
    # method for components
    def UiComponents(self):
  
        # counter value
        self.n = 0
  
        # creating label
        label = QLabel("Counter", self)
  
        # setting label geometry
        label.setGeometry(100, 100, 100, 40)
  
        # creating a command link button
        cl_button = QCommandLinkButton("Next", self)
  
        # setting geometry
        cl_button.setGeometry(200, 100, 200, 40)
  
        # adding action to the button
        cl_button.clicked.connect(lambda: increment(self.n))
  
  
        # method for incrementing the counter
        def increment(n):
              
            # increment
            self.n = n + 1
  
            # setting text to the label
            label.setText(str(self.n))
  
  
# create pyqt5 app
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
# start the app
sys.exit(App.exec())


Output :



Last Updated : 26 Jun, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads