PyQt5 QCommandLinkButton - Setting Border for Checked states

PyQt5 QCommandLinkButton - Setting Border for Checked states

The QCommandLinkButton in PyQt5 is a button that provides a Vista-style command link with a description.

To set a border for the checked state of a QCommandLinkButton, you can use the Qt stylesheet feature. This will let you customize the appearance of the button based on its state.

Here's how you can set a border for a checked QCommandLinkButton:

import sys from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QCommandLinkButton class AppDemo(QWidget): def __init__(self): super().__init__() layout = QVBoxLayout(self) button = QCommandLinkButton("Title", "Description", self) button.setCheckable(True) # Apply stylesheet button.setStyleSheet(""" QCommandLinkButton:checked { border: 2px solid red; } """) layout.addWidget(button) app = QApplication(sys.argv) demo = AppDemo() demo.show() sys.exit(app.exec_()) 

In this example:

  • The button is made checkable using setCheckable(True).
  • The stylesheet sets the border color to red for a checked QCommandLinkButton.

You can adjust the styles as needed for your specific requirements.


More Tags

alert matrix-multiplication rpgle http-status-code-401 nouislider css-grid textarea charts cardlayout ruby

More Programming Guides

Other Guides

More Programming Examples