pyqt5 Set control transparency method: first use the QGraphicsOpacityEffect class to set the transparency effect of the graphic element; then use "element name.setOpacity (transparent value)" to set the transparency of the element, the parameter value is between 0 and "1.0" That’s it.
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
PyQT sets control transparency
PyQT5 sets Opacity for the control, method: QGraphicsOpacityEffect
In the following sample code, myshow is a QPushButton, and the method for setting transparency is as follows :
op = QtWidgets.QGraphicsOpacityEffect() op.setOpacity(0.5) myshow.setGraphicsEffect(op) myshow.setAutoFillBackground(True)
Complete example, you can paste it directly and use it:
from PyQt5 import QtWidgets, QtCore import sys from PyQt5.QtCore import * import time if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) myshow = QtWidgets.QPushButton('Button') myshow.setStyleSheet(""" padding-left: 10px; padding-right: 10px; padding-top: 1px; padding-bottom: 1px; border:1px solid #0073df; border-radius:5px; background: #167ce9; color: #fff; """) def changeOpacity(_): op = QtWidgets.QGraphicsOpacityEffect() op.setOpacity(0.5) myshow.setGraphicsEffect(op) myshow.setAutoFillBackground(True) myshow.clicked.connect(changeOpacity) layout = QtWidgets.QVBoxLayout() layout.addWidget(myshow) main = QtWidgets.QWidget() main.setLayout(layout) main.show() sys.exit(app.exec_())
Related free learning recommendations: python video tutorial!
The above is the detailed content of How to set control transparency in pyqt5. For more information, please follow other related articles on the PHP Chinese website!

Pythonusesahybridmodelofcompilationandinterpretation:1)ThePythoninterpretercompilessourcecodeintoplatform-independentbytecode.2)ThePythonVirtualMachine(PVM)thenexecutesthisbytecode,balancingeaseofusewithperformance.

Pythonisbothinterpretedandcompiled.1)It'scompiledtobytecodeforportabilityacrossplatforms.2)Thebytecodeistheninterpreted,allowingfordynamictypingandrapiddevelopment,thoughitmaybeslowerthanfullycompiledlanguages.

Forloopsareidealwhenyouknowthenumberofiterationsinadvance,whilewhileloopsarebetterforsituationswhereyouneedtoloopuntilaconditionismet.Forloopsaremoreefficientandreadable,suitableforiteratingoversequences,whereaswhileloopsoffermorecontrolandareusefulf

Forloopsareusedwhenthenumberofiterationsisknowninadvance,whilewhileloopsareusedwhentheiterationsdependonacondition.1)Forloopsareidealforiteratingoversequenceslikelistsorarrays.2)Whileloopsaresuitableforscenarioswheretheloopcontinuesuntilaspecificcond

Pythonisnotpurelyinterpreted;itusesahybridapproachofbytecodecompilationandruntimeinterpretation.1)Pythoncompilessourcecodeintobytecode,whichisthenexecutedbythePythonVirtualMachine(PVM).2)Thisprocessallowsforrapiddevelopmentbutcanimpactperformance,req

ToconcatenatelistsinPythonwiththesameelements,use:1)the operatortokeepduplicates,2)asettoremoveduplicates,or3)listcomprehensionforcontroloverduplicates,eachmethodhasdifferentperformanceandorderimplications.

Pythonisaninterpretedlanguage,offeringeaseofuseandflexibilitybutfacingperformancelimitationsincriticalapplications.1)InterpretedlanguageslikePythonexecuteline-by-line,allowingimmediatefeedbackandrapidprototyping.2)CompiledlanguageslikeC/C transformt

Useforloopswhenthenumberofiterationsisknowninadvance,andwhileloopswheniterationsdependonacondition.1)Forloopsareidealforsequenceslikelistsorranges.2)Whileloopssuitscenarioswheretheloopcontinuesuntilaspecificconditionismet,usefulforuserinputsoralgorit


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

Atom editor mac version download
The most popular open source editor

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version
Visual web development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment
