Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use QSlider in Python

Shulou Source: shulou.com Published: 2022-06-02 06:34:23 10月02日 Update

This article introduces how to use QSlider in Python, the content is very detailed, interested friends can refer to, hope to be helpful to you.

1. Qslider control

1. Control introduction and use

Qslider is interpreted as a slider control, which is used to facilitate sliding left and right.

Often this type of sliding is used more for devices that can be touched by the screen.

When we want to use the slider control, we essentially call the Qslider class.

When you use it, you first instantiate the class qslider and then call it.

two。 Orientation of the control

This control can place the Qt.Horizontal horizontally or vertically.

3. The use format of the control

Variable name = Qslider (orientation, parent container)

The horizontal direction value is 1 and the vertical direction value is 2

Application examples:

Sl=QSlider (Qt.Horizontal,self)

3. Configuration of the control

The maximum value setting of the slider control (range setting)

Set the minimum value and call the setMinimum method directly

For example, set the minimum value to 0

Sl.setMinimum (0)

Maximum value setting, call the setMaximum method directly

For example, set the maximum value to 255.

Sl.setMaximum (255)

Sliding value change event of slider

Use format:

Slider object name. ValueChanged [int] .connect (corresponding to slot function)

SL.valueChanged [int] .connect (self.myValue)

II. Review of enumeration

Enumerated classes exist in the QtCore core class library.

An example of the import of this class:

From PyQt5.QtCore import Qt

III. Summary and emphasis

1. Master the use of slider control Qslider

two。 The event of mastering the slider value

3. Master the use of enumerated class libraries

The source code of this section tutorial:

Import sysfrom PyQt5.QtWidgets import QApplication,QWidget,QSliderfrom PyQt5.QtGui import QColorfrom PyQt5.QtCore import Qt

Class MyClass (QWidget): def _ init__ (self): super (MyClass, self). _ _ init__ () self.initUI () def initUI (self): self.setWindowTitle ("Liu Jinyu programming") self.setGeometry (300100400300) sl=QSlider (2 Self) sl.move (50 background-color:black 50) sl.setMinimum (0) sl.setMaximum (255) sl.valueChanged [int] .connect (self.myValue) self.setStyleSheet ("QWidget {background-color:black}") self.show () def myValue (self,a): mycolor=QColor (0Pol 0) 0) mycolor.setBlue (a) self.setStyleSheet ("QWidget {background-color:%s}"% mycolor.name ())

If _ name__== "_ _ main__": app=QApplication (sys.argv) mc=MyClass () app.exec_ ()

On how to use QSlider in Python to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Control direction more maximum minimum event content name method maximum format horizontal help good interest function variable instance container object Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Xiaomi Shulou Tech Info vpn OPPO Reno