PyQt5 QCommandLinkButton – 设置图形效果

PyQt5 QCommandLinkButton – 设置图形效果

在这篇文章中,我们将看到如何为QCommandLinkButton设置图形效果。图形效果可以是阴影、模糊或颜色效果,这些效果可以随时改变,也可以随时创建新的效果。如果这个命令链接按钮上已经安装了一个效果,QWidget会在安装新的效果之前删除现有的效果。

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

语法: button.setGraphicsEffect(effect)

参数: 它需要QGraphicEffect对象作为参数。

返回: 它返回无。

注意: 该方法将对其本身及其所有子对象应用效果。

下面是实现方法

# 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, 200, 50)
  
        # shadow effect
        effect = QGraphicsDropShadowEffect()
        effect.setOffset(20, 20)
  
        # setting effect to the command link button
        cl_button.setGraphicsEffect(effect)
  
          
  
  
  
  
# create pyqt5 app
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
# start the app
sys.exit(App.exec())

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

PyQt5 命令连接按钮控件QCommandLinkButton