当前位置:网站首页>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;
}
边栏推荐
- Nacos usage of micro services
- Blue Bridge Cup: the fourth preliminary - "simulated intelligent irrigation system"
- 2.5 conversion of different data types (2)
- Micro service knowledge sorting - three pieces of micro Service Technology
- About unregistered transfer login page
- How to read the source code [debug and observe the source code]
- Analysis of gas fee setting under eip1559
- Task of gradle learning
- JMeter plug-in installation
- Gym welcomes the first complete environmental document, which makes it easier to get started with intensive learning!
猜你喜欢

Today's work summary and plan: February 14, 2022

JMeter plug-in installation

2.1 use of variables

Shortest path problem of graph theory (acwing template)

Gym welcomes the first complete environmental document, which makes it easier to get started with intensive learning!

Virtual machine installation deepin system

Sparse matrix (triple) creation, transpose, traversal, addition, subtraction, multiplication. C implementation

Machine learning support vector machine SVM

The global industrial design revenue in 2021 was about $44360 million, and it is expected to reach $62720 million in 2028. From 2022 to 2028, the CAGR was 5.5%

2.5 conversion of different data types (2)
随机推荐
Explore the internal mechanism of modern browsers (I) (original translation)
[Yugong series] February 2022 Net architecture class 004 ABP vNext used in WPF project
7. Data broker presentation
Machine learning support vector machine SVM
浅议.NET遗留应用改造
MySQL master-slave synchronization principle
Print linked list from end to end
Microservice knowledge sorting - search technology and automatic deployment technology
How to modify the network IP addresses of mobile phones and computers?
Microservice framework - frequently asked questions
Today's work summary and plan: February 14, 2022
Use of aggregate functions
JMeter plug-in installation
Parental delegation mechanism
Make a simple text logo with DW
FPGA learning notes: vivado 2019.1 project creation
Point cloud data denoising
P5.js development - setting
Bool blind note - score query
Leetcode daily question solution: 540 A single element in an ordered array