Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use QSlider in Python

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 208

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report