当前位置:网站首页>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;
}
边栏推荐
- Instructions for common methods of regular expressions
- Make a simple text logo with DW
- Global and Chinese markets of lithium chloride 2022-2028: Research Report on technology, participants, trends, market size and share
- AcWing 1460. Where am i?
- 2.7 format output of values
- Blue Bridge Cup: the fourth preliminary - "simulated intelligent irrigation system"
- MDM mass data synchronization test verification
- Golang type assertion and conversion (and strconv package)
- 强基计划 数学相关书籍 推荐
- 【c】 Digital bomb
猜你喜欢

19、 MySQL -- SQL statements and queries

Point cloud data denoising

Preliminary practice of niuke.com (11)

Node MySQL serialize cannot rollback transactions

FPGA learning notes: vivado 2019.1 project creation

Task of gradle learning

jvm jni 及 pvm pybind11 大批量数据传输及优化

Change deepin to Alibaba image source

How to handle wechat circle of friends marketing activities and share production and release skills

Use of aggregate functions
随机推荐
Microservice knowledge sorting - search technology and automatic deployment technology
Get log4net log file in C - get log4net log file in C
Professional interpretation | how to become an SQL developer
2166. Design bit set
4. Data binding
Wargames study notes -- Leviathan
FPGA learning notes: vivado 2019.1 project creation
FPGA 学习笔记:Vivado 2019.1 工程创建
Wechat applet quick start (including NPM package use and mobx status management)
Test panghu was teaching you how to use the technical code to flirt with girls online on Valentine's Day 520
Line segment tree blue book explanation + classic example acwing 1275 Maximum number
Global and Chinese markets of polyimide tubes for electronics 2022-2028: Research Report on technology, participants, trends, market size and share
Make a simple text logo with DW
2.2 integer
How to improve data security by renting servers in Hong Kong
Day6 merge two ordered arrays
Assign the CMD command execution result to a variable
Introduction to golang garbage collection
[raid] [simple DP] mine excavation
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