当前位置:网站首页>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;
}
边栏推荐
- Micro service knowledge sorting - asynchronous communication technology
- Global and Chinese market of charity software 2022-2028: Research Report on technology, participants, trends, market size and share
- App compliance
- 4. Data splitting of Flink real-time project
- Detailed and not wordy. Share the win10 tutorial of computer reinstallation system
- Vscode reports an error according to the go plug-in go get connectex: a connection attempt failed because the connected party did not pro
- Line segment tree blue book explanation + classic example acwing 1275 Maximum number
- Global and Chinese market of rubidium standard 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets of active matrix LCD 2022-2028: Research Report on technology, participants, trends, market size and share
- Analysis of gas fee setting under eip1559
猜你喜欢
Explore the internal mechanism of modern browsers (I) (original translation)
Teach you how to quickly recover data by deleting recycle bin files by mistake
How to improve data security by renting servers in Hong Kong
Vscode reports an error according to the go plug-in go get connectex: a connection attempt failed because the connected party did not pro
2.1 use of variables
Shortest path problem of graph theory (acwing template)
String and+
Don't be afraid of no foundation. Zero foundation doesn't need any technology to reinstall the computer system
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
jvm jni 及 pvm pybind11 大批量数据传输及优化
随机推荐
App compliance
Popularize the basics of IP routing
2.5 conversion of different data types (2)
Test changes in Devops mode -- learning and thinking
18、 MySQL -- index
Upgrade PIP and install Libraries
Wargames study notes -- Leviathan
Exercises of function recursion
Do you really know how old you are?
What is the difference between a kill process and a close process- What are the differences between kill process and close process?
6006. Take out the minimum number of magic beans
Sightseeing - statistics of the number of shortest paths + state transfer + secondary small paths
Virtual machine installation deepin system
Based on laravel 5.5\5.6\5 X solution to the failure of installing laravel ide helper
Assign the CMD command execution result to a variable
2.2 integer
Change deepin to Alibaba image source
JMeter plug-in installation
Find a line in a file and remove it
Ruby replaces gem Alibaba image