当前位置:网站首页>9 pyqt5 qscrollarea scroll area and qscrollbar scroll bar
9 pyqt5 qscrollarea scroll area and qscrollbar scroll bar
2022-07-03 20:26:00 【Small clay figurine ginger】
List of articles
Class inheritance relationship is as follows :
1 QScrollArea
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os,sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
#from PyQt5.QtGui import *
class QScrollAreaDemo(QScrollArea):
def __init__(self,*args,**kwargs):
super(QScrollAreaDemo, self).__init__(*args,**kwargs)
self.setWindowTitle("QScrollAreaDemo")
self.resize(400,400)
# as long as setwidget If the size of the scrolling area is larger than the window size, the scrollbar effect will appear
widget = QWidget()
widget.setStyleSheet("background-color:red;")
widget.setMinimumSize(600,600) # Scroll area
self.setWidget(widget)
if __name__ == '__main__':
app = QApplication(sys.argv)
mainwindows = QScrollAreaDemo()
mainwindows.show()
sys.exit(app.exec())
The effect is as follows :
2 QScrollBar
QScrollBar This control provides horizontal or vertical scrollbars , This can expand the effective loading area of the current window , To load more controls .
1 API
2 Signal slot

3 Demo
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os,sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class QScrollBarDemo(QWidget):
def __init__(self,*args,**kwargs):
super(QScrollBarDemo, self).__init__(*args,**kwargs)
self.setWindowTitle("QScrollBarDemo")
self.resize(400,400)
vlayout = QVBoxLayout(self)
self.qscrollbar1 = QScrollBar()
self.qscrollbar1.setOrientation(Qt.Horizontal) # level
self.qscrollbar2 = QScrollBar()
self.qscrollbar2.setOrientation(Qt.Horizontal) # level
self.qscrollbar3 = QScrollBar(Qt.Horizontal)
self.qscrollbar1.setRange(0,255)
self.qscrollbar2.setRange(0, 255)
self.qscrollbar3.setRange(0, 255)
vlayout.addWidget(self.qscrollbar1)
vlayout.addWidget(self.qscrollbar2)
vlayout.addWidget(self.qscrollbar3)
self.showlabel = QLabel(" Laugh all heroes ")
font = QFont("Times", 50, QFont.Bold)
self.showlabel.setFont(font)
vlayout.addWidget(self.showlabel,8)
#
self.qscrollbar1.valueChanged.connect(self.slidermove)
self.qscrollbar2.sliderMoved.connect(self.slidermove)
self.qscrollbar3.sliderMoved.connect(self.slidermove)
def slidermove(self,value):
r = self.qscrollbar1.value()
g = self.qscrollbar2.value()
b = self.qscrollbar3.value()
self.showlabel.setStyleSheet("color:rgb(%s,%s,%s)"%(r,g,b))
if __name__ == '__main__':
app = QApplication(sys.argv)
mainwindows = QScrollBarDemo()
mainwindows.show()
sys.exit(app.exec())
The effect is as follows :
4 Style sheets
Scroll bar is divided horizontally vertical
QScrollBar:horizontal {
border: 2px solid grey;
background: #32CC99;
height: 15px;
margin: 0px 20px 0 20px;
}
QScrollBar::handle:horizontal {
background: white;
min-width: 20px;
}
QScrollBar::add-line:horizontal {
border: 2px solid grey;
background: #32CC99;
width: 20px;
subcontrol-position: right;
subcontrol-origin: margin;
}
QScrollBar::sub-line:horizontal {
border: 2px solid grey;
background: #32CC99;
width: 20px;
subcontrol-position: left;
subcontrol-origin: margin;
}
QScrollBar:left-arrow:horizontal, QScrollBar::right-arrow:horizontal {
border: 2px solid grey;
width: 3px;
height: 3px;
background: white;
}
QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal {
background: none;
}

Vertical style :
QScrollBar:vertical {
background: url(images/scrollbar-vertical-bg.png);
width: 9px;
margin: 0px 0 0px 0;
}
QScrollBar::handle:vertical {
background: rgb(195, 195, 195);
min-height: 20px;
margin: 0 1px 0 2px;
border-radius: 3px;
border: none;
/*background: qlineargradient(spread:reflect,
x1:0, y1:0, x2:1, y2:0,
stop:0 rgba(164, 164, 164, 255),
stop:0.5 rgba(120, 120, 120, 255),
stop:1 rgba(164, 164, 164, 255));*/
/*border-image: url(images/scrollbar-vertical-thumb.png) 8px 0 8px 0 fixed;*/
}
QScrollBar::add-line:vertical {
background: url(images/scrollbar-vertical-bg.png);
height: 0px;
subcontrol-position: bottom;
subcontrol-origin: margin;
}
QScrollBar::sub-line:vertical {
background: url(images/scrollbar-vertical-bg.png);
height: 0px;
subcontrol-position: top;
subcontrol-origin: margin;
}
QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {
border: 1px solid grey;
width: 3px;
height: 3px;
background: white;
}
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
background: none;
}
边栏推荐
- 2.6 formula calculation
- App compliance
- 19、 MySQL -- SQL statements and queries
- Assign the CMD command execution result to a variable
- 2.7 format output of values
- About callback function and hook function
- Golang type assertion and conversion (and strconv package)
- Producer consumer mode (multithreading, use of shared resources)
- How to modify the network IP addresses of mobile phones and computers?
- Nacos usage of micro services
猜你喜欢

In 2021, the global revenue of thick film resistors was about $1537.3 million, and it is expected to reach $2118.7 million in 2028

Popularize the basics of IP routing

你真的知道自己多大了吗?

Promethus

Virtual machine installation deepin system
![[effective Objective-C] - block and grand central distribution](/img/09/22b979b97ea13d649b4b904637b79f.jpg)
[effective Objective-C] - block and grand central distribution

44. Concurrent programming theory

Typora charges, WTF? Still need support

Nerfplusplus parameter format sorting

Wechat applet quick start (including NPM package use and mobx status management)
随机推荐
JVM JNI and PVM pybind11 mass data transmission and optimization
Bool blind note - score query
Sparse matrix (triple) creation, transpose, traversal, addition, subtraction, multiplication. C implementation
February 14-20, 2022 (osgear source code debugging +ue4 video +ogremain source code transcription)
Analysis of gas fee setting under eip1559
Global and Chinese markets of polyimide tubes for electronics 2022-2028: Research Report on technology, participants, trends, market size and share
4. Data splitting of Flink real-time project
47. Process lock & process pool & Collaboration
Qtablewidget control of QT
Rad+xray vulnerability scanning tool
Network security Kali penetration learning how to get started with web penetration how to scan based on nmap
How to check the permission to write to a directory or file- How do you check for permissions to write to a directory or file?
Wechat applet quick start (including NPM package use and mobx status management)
Node MySQL serialize cannot rollback transactions
Sightseeing - statistics of the number of shortest paths + state transfer + secondary small paths
About unregistered transfer login page
浅议.NET遗留应用改造
Professional interpretation | how to become an SQL developer
It is discussed that the success of Vit lies not in attention. Shiftvit uses the precision of swing transformer to outperform the speed of RESNET
强基计划 数学相关书籍 推荐