📌  相关文章
📜  PyQt5 QCommandLinkButton – 设置自动默认属性

📅  最后修改于: 2022-05-13 01:55:51.382000             🧑  作者: Mango

PyQt5 QCommandLinkButton – 设置自动默认属性

在本文中,我们将了解如何设置 QCommandLinkButton 的自动默认属性。如果此属性设置为 true,则命令链接按钮是自动默认按钮。在某些 GUI 样式中,默认按钮的绘制周围有一个额外的框架,最多 3 个像素或更多。 Qt 会自动在自动默认按钮周围留出这个空间,即自动默认按钮可能有稍大的尺寸提示。

为了做到这一点,我们使用setAutoDefault方法和命令链接按钮对象

下面是实现

# 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):
  
  
        # creating a command link button
        cl_button = QCommandLinkButton("Press", self)
  
        # setting geometry
        cl_button.setGeometry(250, 100, 150, 50)
  
        # making it checkable
        cl_button.setCheckable(True)
  
        # setting auto default property
        cl_button.setAutoDefault(True)
  
        # size
        size = QSize(30, 30)
  
        # setting icon size
        cl_button.setIconSize(size)
  
  
  
# create pyqt5 app
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
# start the app
sys.exit(App.exec())

输出 :