提交 710e27a1 编写于 作者: 之一Yo's avatar 之一Yo

添加滚动条,#160

上级 2283b5e3
......@@ -3,7 +3,7 @@ from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtGui import QPixmap, QDesktopServices
from PyQt5.QtWidgets import QFrame, QLabel, QVBoxLayout, QWidget, QHBoxLayout
from qfluentwidgets import IconWidget, FluentIcon, TextWrap, ScrollArea
from qfluentwidgets import IconWidget, FluentIcon, TextWrap, SingleDirectionScrollArea
from ..common.style_sheet import StyleSheet
......@@ -45,7 +45,7 @@ class LinkCard(QFrame):
QDesktopServices.openUrl(self.url)
class LinkCardView(ScrollArea):
class LinkCardView(SingleDirectionScrollArea):
""" Link card view """
def __init__(self, parent=None):
......
......@@ -49,37 +49,3 @@ ExampleCard>#titleLabel {
color: white;
font: 14px 'Segoe UI', 'Microsoft YaHei';
}
QScrollBar {
background: transparent;
width: 4px;
margin-top: 132px;
margin-bottom: 0;
padding-right: 2px;
}
#imageViewer QScrollBar {
margin-top: 0px;
}
/*隐藏上箭头*/
QScrollBar::sub-line {
background: transparent;
}
/*隐藏下箭头*/
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
min-height: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical {
background: none;
}
\ No newline at end of file
......@@ -16,34 +16,3 @@ BannerWidget > #galleryLabel {
color: white;
padding-left: 28px;
}
QScrollBar {
background: transparent;
width: 4px;
margin-top: 32px;
margin-bottom: 0;
padding-right: 2px;
}
/*隐藏上箭头*/
QScrollBar::sub-line {
background: transparent;
}
/*隐藏下箭头*/
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
min-height: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical {
background: none;
}
\ No newline at end of file
......@@ -60,32 +60,3 @@ IconInfoPanel>QLabel {
color: rgb(207, 207, 207);
}
QScrollBar {
background: transparent;
width: 4px;
margin-top: 10px;
margin-bottom: 0;
padding-right: 2px;
}
QScrollBar::sub-line {
background: transparent;
}
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
min-height: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical {
background: none;
}
\ No newline at end of file
......@@ -15,34 +15,3 @@ QLabel#settingLabel {
color: white;
}
/* 滚动条 */
QScrollBar {
background: transparent;
width: 4px;
margin-top: 32px;
margin-bottom: 0;
padding-right: 2px;
}
/*隐藏上箭头*/
QScrollBar::sub-line {
background: transparent;
}
/*隐藏下箭头*/
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
min-height: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical {
background: none;
}
\ No newline at end of file
......@@ -46,37 +46,3 @@ ExampleCard > #titleLabel {
color: black;
font: 14px 'Segoe UI', 'Microsoft YaHei';
}
QScrollBar {
background: transparent;
width: 4px;
margin-top: 132px;
margin-bottom: 0;
padding-right: 2px;
}
#imageViewer QScrollBar {
margin-top: 0px;
}
QScrollBar::sub-line {
background: transparent;
}
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
min-height: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical {
background: none;
}
\ No newline at end of file
......@@ -17,32 +17,3 @@ BannerWidget > #galleryLabel {
}
QScrollBar {
background: transparent;
width: 4px;
margin-top: 32px;
margin-bottom: 0;
padding-right: 2px;
}
/*隐藏上箭头*/
QScrollBar::sub-line {
background: transparent;
}
/*隐藏下箭头*/
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
min-height: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical {
background: none;
}
\ No newline at end of file
......@@ -61,33 +61,3 @@ IconInfoPanel > QLabel {
background-color: transparent;
color: black;
}
QScrollBar {
background: transparent;
width: 4px;
margin-top: 10px;
margin-bottom: 0;
padding-right: 2px;
}
QScrollBar::sub-line {
background: transparent;
}
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
min-height: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical {
background: none;
}
\ No newline at end of file
......@@ -13,35 +13,3 @@ QLabel#settingLabel {
font: 33px 'Microsoft YaHei Light';
background-color: transparent;
}
/* 滚动条 */
QScrollBar {
background: transparent;
width: 4px;
margin-top: 32px;
margin-bottom: 0;
padding-right: 2px;
}
/*隐藏上箭头*/
QScrollBar::sub-line {
background: transparent;
}
/*隐藏下箭头*/
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
min-height: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical {
background: none;
}
\ No newline at end of file
......@@ -77,7 +77,10 @@ class BannerWidget(QWidget):
path = path.simplified()
# draw background color
painter.fillPath(path, QColor(206, 216, 228))
if not isDarkTheme():
painter.fillPath(path, QColor(206, 216, 228))
else:
painter.fillPath(path, QColor(0, 0, 0))
# draw banner image
pixmap = self.banner.scaled(
......
......@@ -2,7 +2,7 @@
from PyQt5.QtCore import Qt, QEasingCurve
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QWidget
from qfluentwidgets import ScrollArea, SmoothScrollArea, ToolTipFilter, PixmapLabel
from qfluentwidgets import SingleDirectionScrollArea, SmoothScrollArea, ToolTipFilter, PixmapLabel
from .gallery_interface import GalleryInterface
from ..common.translator import Translator
......@@ -19,7 +19,7 @@ class ScrollInterface(GalleryInterface):
parent=parent
)
w = ScrollArea()
w = SingleDirectionScrollArea()
label = PixmapLabel(self)
label.setPixmap(QPixmap(":/gallery/images/chidanta2.jpg").scaled(
775, 1229, Qt.KeepAspectRatio, Qt.SmoothTransformation
......@@ -27,7 +27,7 @@ class ScrollInterface(GalleryInterface):
w.horizontalScrollBar().setValue(0)
w.setWidget(label)
w.setFixedSize(780, 430)
w.setFixedSize(775, 430)
w.setObjectName('imageViewer')
card = self.addExampleCard(
......@@ -44,7 +44,7 @@ class ScrollInterface(GalleryInterface):
label.setPixmap(QPixmap(":/gallery/images/chidanta3.jpg"))
w.setWidget(label)
w.setFixedSize(659, 540)
w.setFixedSize(654, 540)
w.setObjectName('imageViewer')
card = self.addExampleCard(
......
......@@ -3,6 +3,7 @@ import os
import sys
from PyQt5.QtCore import Qt, QTranslator
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import QApplication
from qfluentwidgets import FluentTranslator
......@@ -25,6 +26,11 @@ QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
app = QApplication(sys.argv)
app.setAttribute(Qt.AA_DontCreateNativeWidgetSiblings)
# font anti aliasing
font = app.font()
font.setHintingPreference(QFont.PreferNoHinting)
app.setFont(font)
# internationalization
locale = cfg.get(cfg.language).value
translator = FluentTranslator(locale)
......
QScrollBar:vertical {
background: transparent;
width: 5px;
padding-right: 2px;
}
QScrollBar:horizontal {
background: transparent;
height: 5px;
padding-bottom: 2px;
}
/*隐藏上箭头*/
QScrollBar::sub-line {
background: transparent;
}
/*隐藏下箭头*/
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
}
QScrollBar::handle:vertical {
min-height: 40px;
}
QScrollBar::handle:horizontal {
min-width: 40px;
}
QScrollBar::add-page,
QScrollBar::sub-page {
background: none;
QScrollArea {
border: none;
}
\ No newline at end of file
......@@ -15,34 +15,3 @@ QLabel#settingLabel {
color: white;
}
/* 滚动条 */
QScrollBar {
background: transparent;
width: 4px;
margin-top: 32px;
margin-bottom: 0;
padding-right: 2px;
}
/*隐藏上箭头*/
QScrollBar::sub-line {
background: transparent;
}
/*隐藏下箭头*/
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
min-height: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical {
background: none;
}
\ No newline at end of file
......@@ -14,34 +14,3 @@ QLabel#settingLabel {
background-color: transparent;
}
/* 滚动条 */
QScrollBar {
background: transparent;
width: 4px;
margin-top: 32px;
margin-bottom: 0;
padding-right: 2px;
}
/*隐藏上箭头*/
QScrollBar::sub-line {
background: transparent;
}
/*隐藏下箭头*/
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
min-height: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical {
background: none;
}
\ No newline at end of file
......@@ -21,7 +21,7 @@ class Demo(QWidget):
self.view.setModel(model)
self.hBoxLayout.addWidget(self.view)
self.hBoxLayout.setContentsMargins(30, 30, 30, 30)
self.hBoxLayout.setContentsMargins(0, 0, 0, 0)
self.resize(700, 600)
......
<?xml version="1.0" encoding="utf-8"?>
<svg id="" width="16" height="16" style="width:16px;height:16px;" version="1.1"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2048 2048" enable-background="new 0 0 2048 2048"
xml:space="preserve"><path fill="#5E5E5E" transform="translate(0, 400)" d="M0 184 q0 -37.71 13.71 -70.86 q13.71 -33.14 38.28 -58.29 q24.57 -25.15 57.14 -40 q32.57 -14.86 70.29 -14.86 l1689.14 0 q37.72 0 70.29 14.86 q32.57 14.86 57.14 40 q24.57 25.14 38.28 58.29 q13.72 33.14 13.72 70.86 q0 68.57 -44.57 120 l-790.86 924.57 q-36.57 42.29 -84.57 65.14 q-48 22.86 -104 22.86 q-56 0 -104 -22.86 q-48 -22.86 -84.57 -65.14 l-790.86 -924.57 q-44.57 -51.43 -44.57 -120 Z"/></svg>
\ No newline at end of file
xml:space="preserve"><path fill="#000000" transform="translate(0, 400)" d="M0 184 q0 -37.71 13.71 -70.86 q13.71 -33.14 38.28 -58.29 q24.57 -25.15 57.14 -40 q32.57 -14.86 70.29 -14.86 l1689.14 0 q37.72 0 70.29 14.86 q32.57 14.86 57.14 40 q24.57 25.14 38.28 58.29 q13.72 33.14 13.72 70.86 q0 68.57 -44.57 120 l-790.86 924.57 q-36.57 42.29 -84.57 65.14 q-48 22.86 -104 22.86 q-56 0 -104 -22.86 q-48 -22.86 -84.57 -65.14 l-790.86 -924.57 q-44.57 -51.43 -44.57 -120 Z"/></svg>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<svg id="" width="16" height="16" style="width:16px;height:16px;" version="1.1"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2048 2048" enable-background="new 0 0 2048 2048"
xml:space="preserve"><path fill="#000000" d="M256 1024 q0 -94 44 -176.5 q44 -82.5 121 -135.5 l969 -666 q34 -23 69 -34.5 q35 -11.5 77 -11.5 q52 0 99 20 q47 20 81.5 54.5 q34.5 34.5 55 80.5 q20.5 46 20.5 99 l0 1540 q0 53 -20.5 99 q-20.5 46 -55 80.5 q-34.5 34.5 -81.5 54.5 q-47 20 -99 20 q-79 0 -146 -46 l-969 -666 q-77 -53 -121 -135.5 q-44 -82.5 -44 -176.5 Z"/></svg>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<svg id="" width="16" height="16" style="width:16px;height:16px;" version="1.1"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2048 2048" enable-background="new 0 0 2048 2048"
xml:space="preserve"><path fill="#FFFFFF" d="M256 1024 q0 -94 44 -176.5 q44 -82.5 121 -135.5 l969 -666 q34 -23 69 -34.5 q35 -11.5 77 -11.5 q52 0 99 20 q47 20 81.5 54.5 q34.5 34.5 55 80.5 q20.5 46 20.5 99 l0 1540 q0 53 -20.5 99 q-20.5 46 -55 80.5 q-34.5 34.5 -81.5 54.5 q-47 20 -99 20 q-79 0 -146 -46 l-969 -666 q-77 -53 -121 -135.5 q-44 -82.5 -44 -176.5 Z"/></svg>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<svg id="" width="16" height="16" style="width:16px;height:16px;" version="1.1"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2048 2048" enable-background="new 0 0 2048 2048"
xml:space="preserve"><path fill="#000000" d="M256 1794 l0 -1540 q0 -53 20.5 -99 q20.5 -46 55 -80.5 q34.5 -34.5 81 -54.5 q46.5 -20 99.5 -20 q79 0 146 46 l969 666 q78 54 121.5 136 q43.5 82 43.5 176 q0 94 -43.5 176 q-43.5 82 -121.5 136 l-969 666 q-67 46 -146 46 q-53 0 -99.5 -20 q-46.5 -20 -81 -54.5 q-34.5 -34.5 -55 -80.5 q-20.5 -46 -20.5 -99 Z"/></svg>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<svg id="" width="16" height="16" style="width:16px;height:16px;" version="1.1"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2048 2048" enable-background="new 0 0 2048 2048"
xml:space="preserve"><path fill="#FFFFFF" d="M256 1794 l0 -1540 q0 -53 20.5 -99 q20.5 -46 55 -80.5 q34.5 -34.5 81 -54.5 q46.5 -20 99.5 -20 q79 0 146 46 l969 666 q78 54 121.5 136 q43.5 82 43.5 176 q0 94 -43.5 176 q-43.5 82 -121.5 136 l-969 666 q-67 46 -146 46 q-53 0 -99.5 -20 q-46.5 -20 -81 -54.5 q-34.5 -34.5 -55 -80.5 q-20.5 -46 -20.5 -99 Z"/></svg>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<svg id="" width="16" height="16" style="width:16px;height:16px;" version="1.1"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2048 2048" enable-background="new 0 0 2048 2048"
xml:space="preserve"><path fill="#5E5E5E" transform="translate(0, 350)" d="M179.43 1316.57 q-37.72 0 -70.29 -14.86 q-32.57 -14.86 -57.14 -40 q-24.57 -25.14 -38.28 -58.29 q-13.71 -33.14 -13.71 -70.86 q0 -68.57 44.57 -120 l790.86 -924.57 q36.57 -42.29 84.57 -65.14 q48 -22.86 104 -22.86 q113.14 0 188.57 88 l790.86 924.57 q44.57 51.43 44.57 120 q0 37.72 -13.72 70.86 q-13.71 33.14 -38.28 58.29 q-24.57 25.14 -57.14 40 q-32.57 14.86 -70.29 14.86 l-1689.14 0 Z"/></svg>
\ No newline at end of file
xml:space="preserve"><path fill="#000000" transform="translate(0, 350)" d="M179.43 1316.57 q-37.72 0 -70.29 -14.86 q-32.57 -14.86 -57.14 -40 q-24.57 -25.14 -38.28 -58.29 q-13.71 -33.14 -13.71 -70.86 q0 -68.57 44.57 -120 l790.86 -924.57 q36.57 -42.29 84.57 -65.14 q48 -22.86 104 -22.86 q113.14 0 188.57 88 l790.86 924.57 q44.57 51.43 44.57 120 q0 37.72 -13.72 70.86 q-13.71 33.14 -38.28 58.29 q-24.57 25.14 -57.14 40 q-32.57 14.86 -70.29 14.86 l-1689.14 0 Z"/></svg>
\ No newline at end of file
......@@ -86,37 +86,6 @@ QSlider::handle:horizontal:disabled {
}
/* 滚动条 */
QScrollBar {
background: transparent;
width: 4px;
margin-top: 32px;
padding-right: 1px;
}
/*隐藏上箭头*/
QScrollBar::sub-line {
background: transparent;
}
/*隐藏下箭头*/
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
min-height: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical {
background: none;
}
#cancelButton {
background: rgb(45, 45, 45);
border: 1px solid rgb(48, 48, 48);
......
......@@ -50,35 +50,6 @@ QScrollArea{
background-color: rgb(23, 23, 23);
}
/*滚动条*/
QScrollBar:vertical {
background: transparent;
border: none;
width: 3px;
}
/*隐藏上箭头*/
QScrollBar::sub-line {
background: transparent;
}
/*隐藏下箭头*/
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(128, 128, 128);
min-height: 40px;
border: 1px solid transparent;
border-radius: 1px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical {
background: none;
}
#scrollWidget{
border: none;
......
......@@ -51,49 +51,3 @@ LineEdit:disabled, TextEdit:disabled, PlainTextEdit:disabled {
#lineEditButton:pressed {
background-color: rgba(255, 255, 255, 6);
}
QScrollBar {
background: transparent;
width: 4px;
margin-top: 12px;
margin-bottom: 0;
padding-right: 2px;
}
QScrollBar:horizontal {
background: transparent;
height: 4px;
margin-left: 12px;
margin-right: 12px;
padding-bottom: 2px;
}
QScrollBar::sub-line {
background: transparent;
}
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
}
QScrollBar::handle:vertical {
min-height: 32px;
}
QScrollBar::handle:horizontal {
min-width: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical,
QScrollBar::add-page:horizontal,
QScrollBar::sub-page:horizontal {
background: none;
}
\ No newline at end of file
......@@ -120,46 +120,3 @@ QHeaderView::up-arrow {
margin-right: 6px;
image: url(:/qfluentwidgets/images/table_view/Up_white.svg);
}
QScrollBar:vertical {
background: transparent;
width: 4px;
margin-top: 50px;
margin-bottom: 0;
padding-right: 2px;
}
QScrollBar:horizontal {
background: transparent;
height: 4px;
padding-bottom: 2px;
}
QScrollBar::sub-line {
background: transparent;
}
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
}
QScrollBar::handle:vertical {
min-height: 32px;
}
QScrollBar::handle:horizontal {
min-width: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical,
QScrollBar::add-page:horizontal,
QScrollBar::sub-page:horizontal {
background: none;
}
\ No newline at end of file
......@@ -85,46 +85,4 @@ QTreeView::indicator:checked:disabled,
QTreeView::indicator:indeterminate:disabled {
border: 1px solid rgb(82, 82, 82);
background-color: rgb(82, 82, 82);
}
QScrollBar:vertical {
background: transparent;
width: 4px;
margin-top: 50px;
margin-bottom: 0;
padding-right: 2px;
}
QScrollBar:horizontal {
background: transparent;
height: 4px;
padding-bottom: 2px;
}
QScrollBar::sub-line {
background: transparent;
}
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
}
QScrollBar::handle:vertical {
min-height: 32px;
}
QScrollBar::handle:horizontal {
min-width: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical,
QScrollBar::add-page:horizontal,
QScrollBar::sub-page:horizontal {
background: none;
}
\ No newline at end of file
......@@ -84,35 +84,6 @@ QSlider::handle:horizontal:disabled {
}
/* 滚动条 */
QScrollBar {
background: transparent;
width: 4px;
margin-top: 32px;
padding-right: 1px;
}
/*隐藏上箭头*/
QScrollBar::sub-line {
background: transparent;
}
/*隐藏下箭头*/
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
min-height: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical {
background: none;
}
#cancelButton {
color: black;
......
......@@ -47,32 +47,6 @@ QScrollArea{
border: none;
}
QScrollBar:vertical {
background: white;
border: none;
width: 3px;
}
QScrollBar::sub-line {
background: transparent;
}
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(128, 128, 128);
min-height: 32px;
border: 1px solid transparent;
border-radius: 1px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical {
background: none;
}
#scrollWidget{
border: none;
......
......@@ -52,49 +52,3 @@ PlainTextEdit:disabled {
#lineEditButton:pressed {
background-color: rgba(0, 0, 0, 6);
}
QScrollBar:vertical {
background: transparent;
width: 4px;
margin-top: 12px;
margin-bottom: 12px;
padding-right: 2px;
}
QScrollBar:horizontal {
background: transparent;
height: 4px;
margin-left: 12px;
margin-right: 12px;
padding-bottom: 2px;
}
QScrollBar::sub-line {
background: transparent;
}
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
}
QScrollBar::handle:vertical {
min-height: 32px;
}
QScrollBar::handle:horizontal {
min-width: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical,
QScrollBar::add-page:horizontal,
QScrollBar::sub-page:horizontal {
background: none;
}
\ No newline at end of file
......@@ -120,47 +120,3 @@ QHeaderView::up-arrow {
margin-right: 6px;
image: url(:/qfluentwidgets/images/table_view/Up_black.svg);
}
QScrollBar:vertical {
background: transparent;
width: 4px;
margin-top: 50px;
margin-bottom: 0;
padding-right: 2px;
}
QScrollBar:horizontal {
background: transparent;
height: 4px;
padding-bottom: 2px;
}
QScrollBar::sub-line {
background: transparent;
}
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
}
QScrollBar::handle:vertical {
min-height: 32px;
}
QScrollBar::handle:horizontal {
min-width: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical,
QScrollBar::add-page:horizontal,
QScrollBar::sub-page:horizontal {
background: none;
}
\ No newline at end of file
......@@ -85,46 +85,3 @@ QTreeView::indicator:indeterminate:disabled {
border: 1px solid rgb(199, 199, 199);
background-color: rgb(199, 199, 199);
}
QScrollBar:vertical {
background: transparent;
width: 4px;
margin-top: 50px;
margin-bottom: 0;
padding-right: 2px;
}
QScrollBar:horizontal {
background: transparent;
height: 4px;
padding-bottom: 2px;
}
QScrollBar::sub-line {
background: transparent;
}
QScrollBar::add-line {
background: transparent;
}
QScrollBar::handle {
background: rgb(122, 122, 122);
border: 2px solid rgb(128, 128, 128);
border-radius: 1px;
}
QScrollBar::handle:vertical {
min-height: 32px;
}
QScrollBar::handle:horizontal {
min-width: 32px;
}
QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical,
QScrollBar::add-page:horizontal,
QScrollBar::sub-page:horizontal {
background: none;
}
\ No newline at end of file
此差异已折叠。
......@@ -165,6 +165,14 @@
<file>images/icons/DateTime_white.svg</file>
<file>images/icons/Basketball_black.svg</file>
<file>images/icons/Basketball_white.svg</file>
<file>images/icons/CareDownSolid_black.svg</file>
<file>images/icons/CareDownSolid_white.svg</file>
<file>images/icons/CareUpSolid_black.svg</file>
<file>images/icons/CareUpSolid_white.svg</file>
<file>images/icons/CareLeftSolid_black.svg</file>
<file>images/icons/CareLeftSolid_white.svg</file>
<file>images/icons/CareRightSolid_black.svg</file>
<file>images/icons/CareRightSolid_white.svg</file>
<file>images/acrylic/noise.png</file>
<file>images/folder_list_dialog/Close_white.png</file>
<file>images/folder_list_dialog/Close_black.png</file>
......@@ -190,10 +198,6 @@
<file>images/tree_view/TreeViewOpen_black.svg</file>
<file>images/tree_view/TreeViewClose_white.svg</file>
<file>images/tree_view/TreeViewOpen_white.svg</file>
<file>images/time_picker/Up_white.svg</file>
<file>images/time_picker/Up_black.svg</file>
<file>images/time_picker/Down_white.svg</file>
<file>images/time_picker/Down_black.svg</file>
<file>images/table_view/Up_black.svg</file>
<file>images/table_view/Up_white.svg</file>
<file>images/table_view/Down_black.svg</file>
......
......@@ -283,8 +283,12 @@ class FluentIcon(FluentIconBase, Enum):
ARROW_DOWN = "ChevronDown"
TRANSPARENT = "Transparent"
MUSIC_FOLDER = "MusicFolder"
CARE_UP_SOLID = "CareUpSolid"
CHEVRON_RIGHT = "ChevronRight"
CARE_DOWN_SOLID = "CareDownSolid"
CARE_LEFT_SOLID = "CareLeftSolid"
BACKGROUND_FILL = "BackgroundColor"
CARE_RIGHT_SOLID = "CareRightSolid"
def path(self, theme=Theme.AUTO):
return f':/qfluentwidgets/images/icons/{self.value}_{getIconColor(theme)}.svg'
......
......@@ -5,7 +5,7 @@ from PyQt5.QtGui import (QBrush, QColor, QPixmap,
from PyQt5.QtWidgets import QApplication, QLabel, QWidget, QPushButton, QFrame, QVBoxLayout
from ...common.style_sheet import FluentStyleSheet, isDarkTheme
from ..widgets import Slider, ScrollArea, PushButton, PrimaryPushButton
from ..widgets import Slider, SingleDirectionScrollArea, PushButton, PrimaryPushButton
from ..widgets.line_edit import LineEdit
from .mask_dialog_base import MaskDialogBase
......@@ -242,7 +242,7 @@ class ColorDialog(MaskDialogBase):
self.oldColor = QColor(color)
self.color = QColor(color)
self.scrollArea = ScrollArea(self.widget)
self.scrollArea = SingleDirectionScrollArea(self.widget)
self.scrollWidget = QWidget(self.scrollArea)
self.buttonGroup = QFrame(self.widget)
......
......@@ -12,7 +12,7 @@ from ...common.icon import getIconColor
from ...common.style_sheet import FluentStyleSheet
from .dialog import Dialog
from .mask_dialog_base import MaskDialogBase
from ..widgets.scroll_area import ScrollArea
from ..widgets.scroll_area import SingleDirectionScrollArea
class FolderListDialog(MaskDialogBase):
......@@ -30,7 +30,7 @@ class FolderListDialog(MaskDialogBase):
self.vBoxLayout = QVBoxLayout(self.widget)
self.titleLabel = QLabel(title, self.widget)
self.contentLabel = QLabel(content, self.widget)
self.scrollArea = ScrollArea(self.widget)
self.scrollArea = SingleDirectionScrollArea(self.widget)
self.scrollWidget = QWidget(self.scrollArea)
self.completeButton = QPushButton(self.tr('Done'), self.widget)
self.addFolderCard = AddFolderCard(self.scrollWidget)
......@@ -53,6 +53,7 @@ class FolderListDialog(MaskDialogBase):
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setWidget(self.scrollWidget)
self.scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.scrollArea.hScrollBar.setForceHidden(True)
self.__initLayout()
# connect signal to slot
......
......@@ -7,7 +7,7 @@ from PyQt5.QtGui import QResizeEvent, QIcon
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QFrame, QApplication
from .navigation_widget import NavigationPushButton, NavigationToolButton, NavigationWidget, NavigationSeparator
from ..widgets.scroll_area import ScrollArea
from ..widgets.scroll_area import SingleDirectionScrollArea
from ...common.style_sheet import FluentStyleSheet
from ...common.icon import FluentIconBase
from ...common.icon import FluentIcon as FIF
......@@ -39,7 +39,7 @@ class NavigationPanel(QFrame):
self._isMenuButtonVisible = True
self._isReturnButtonVisible = False
self.scrollArea = ScrollArea(self)
self.scrollArea = SingleDirectionScrollArea(self)
self.scrollWidget = QWidget()
self.menuButton = NavigationToolButton(FIF.MENU, self)
......
......@@ -8,7 +8,7 @@ from .icon_widget import IconWidget
from .label import PixmapLabel
from .menu import DWMMenu, LineEditMenu, RoundMenu
from .info_bar import InfoBar, InfoBarIcon, InfoBarPosition
from .scroll_area import ScrollArea, SmoothMode, SmoothScrollArea, SmoothScrollBar
from .scroll_area import SingleDirectionScrollArea, SmoothMode, SmoothScrollArea, ScrollArea
from .slider import Slider, HollowHandleStyle
from .spin_box import SpinBox, DoubleSpinBox, DateEdit, DateTimeEdit, TimeEdit
from .stacked_widget import PopUpAniStackedWidget, OpacityAniStackedWidget
......@@ -17,4 +17,5 @@ from .switch_button import SwitchButton, IndicatorPosition
from .table_view import TableView, TableWidget, TableItemDelegate
from .tool_tip import ToolTip, ToolTipFilter
from .tree_view import TreeWidget, TreeView
from .cycle_list_widget import CycleListWidget
\ No newline at end of file
from .cycle_list_widget import CycleListWidget
from .scroll_bar import ScrollBar, SmoothScrollBar, SmoothScrollDelegate
\ No newline at end of file
# coding:utf-8
from enum import Enum
from typing import Iterable
from PyQt5.QtCore import Qt, pyqtSignal, QSize, QEvent, QRectF, QPoint
from PyQt5.QtCore import Qt, pyqtSignal, QSize, QEvent, QRectF
from PyQt5.QtGui import QPainter
from PyQt5.QtWidgets import QWidget, QListWidget, QListWidgetItem, QToolButton, QStyledItemDelegate
from PyQt5.QtWidgets import QListWidget, QListWidgetItem, QToolButton
from .scroll_area import SmoothScrollBar
from ...common.icon import FluentIconBase, Theme, getIconColor
from ...common.style_sheet import themeColor, isDarkTheme
class ScrollIcon(FluentIconBase, Enum):
""" Scroll icon """
UP = "Up"
DOWN = "Down"
def path(self, theme=Theme.AUTO):
return f':/qfluentwidgets/images/time_picker/{self.value}_{getIconColor(theme)}.svg'
from ...common.icon import FluentIcon, isDarkTheme
class ScrollButton(QToolButton):
""" Scroll button """
def __init__(self, icon: ScrollIcon, parent=None):
def __init__(self, icon: FluentIcon, parent=None):
super().__init__(parent=parent)
self._icon = icon
self.isPressed = False
......@@ -53,7 +41,11 @@ class ScrollButton(QToolButton):
x = (self.width() - w) / 2
y = (self.height() - h) / 2
self._icon.render(painter, QRectF(x, y, w, h))
if not isDarkTheme():
self._icon.render(painter, QRectF(x, y, w, h), fill="#5e5e5e")
else:
self._icon.render(painter, QRectF(x, y, w, h))
class CycleListWidget(QListWidget):
......@@ -81,20 +73,20 @@ class CycleListWidget(QListWidget):
self.itemSize = itemSize
self.align = align
self.upButton = ScrollButton(ScrollIcon.UP, self)
self.downButton = ScrollButton(ScrollIcon.DOWN, self)
self.upButton = ScrollButton(FluentIcon.CARE_UP_SOLID, self)
self.downButton = ScrollButton(FluentIcon.CARE_DOWN_SOLID, self)
self.scrollDuration = 250
self.originItems = list(items)
self.vScrollBar = SmoothScrollBar(self)
self.vScrollBar = SmoothScrollBar(Qt.Vertical, self)
self.visibleNumber = 9
# repeat adding items to achieve circular scrolling
self.setItems(items)
self.setVerticalScrollMode(self.ScrollPerPixel)
self.setVerticalScrollBar(self.vScrollBar)
self.vScrollBar.setScrollAnimation(self.scrollDuration)
self.vScrollBar.setForceHidden(True)
self.setViewportMargins(0, 0, 0, 0)
self.setFixedSize(itemSize.width()+8,
......
......@@ -7,8 +7,8 @@ from PyQt5.QtWidgets import QHBoxLayout, QLineEdit, QToolButton, QTextEdit, QPla
from ...common.style_sheet import FluentStyleSheet, themeColor
from ...common.icon import isDarkTheme, FluentIconBase, drawIcon
from ...common.icon import FluentIcon as FIF
from ...common.smooth_scroll import SmoothMode, SmoothScroll
from .menu import LineEditMenu, TextEditMenu
from .scroll_bar import SmoothScrollDelegate
class LineEditButton(QToolButton):
......@@ -153,36 +153,23 @@ class TextEdit(QTextEdit):
def __init__(self, parent=None):
super().__init__(parent=parent)
self.verticalSmoothScroll = SmoothScroll(self, Qt.Vertical)
self.horizonSmoothScroll = SmoothScroll(self, Qt.Horizontal)
self.installEventFilter(SmoothScrollDelegate(self))
FluentStyleSheet.LINE_EDIT.apply(self)
def contextMenuEvent(self, e):
menu = TextEditMenu(self)
menu.exec_(e.globalPos())
def wheelEvent(self, e):
if e.modifiers() == Qt.NoModifier:
self.verticalSmoothScroll.wheelEvent(e)
else:
self.horizonSmoothScroll.wheelEvent(e)
class PlainTextEdit(QPlainTextEdit):
""" Plain text edit """
def __init__(self, parent=None):
super().__init__(parent=parent)
self.verticalSmoothScroll = SmoothScroll(self, Qt.Vertical)
self.horizonSmoothScroll = SmoothScroll(self, Qt.Horizontal)
self.installEventFilter(SmoothScrollDelegate(self))
FluentStyleSheet.LINE_EDIT.apply(self)
def contextMenuEvent(self, e):
menu = TextEditMenu(self)
menu.exec_(e.globalPos())
def wheelEvent(self, e):
if e.modifiers() == Qt.NoModifier:
self.verticalSmoothScroll.wheelEvent(e)
else:
self.horizonSmoothScroll.wheelEvent(e)
......@@ -131,6 +131,7 @@ class MenuActionListWidget(QListWidget):
def wheelEvent(self, e):
self.smoothScroll.wheelEvent(e)
e.setAccepted(True)
def insertItem(self, row, item):
""" inserts menu item at the position in the list given by row """
......
# coding:utf-8
from PyQt5.QtCore import QEasingCurve, Qt, pyqtSignal, QPropertyAnimation, QEvent
from PyQt5.QtGui import QWheelEvent, QKeyEvent
from PyQt5.QtWidgets import QScrollArea, QScrollBar
import typing
from PyQt5.QtCore import QEasingCurve, Qt
from PyQt5.QtGui import QWheelEvent
from PyQt5.QtWidgets import QScrollArea, QWidget
from ...common.smooth_scroll import SmoothScroll, SmoothMode
from .scroll_bar import ScrollBar, SmoothScrollBar, SmoothScrollDelegate
class ScrollArea(QScrollArea):
""" A scroll area which can scroll smoothly """
""" Smooth scroll area """
def __init__(self, parent=None):
super().__init__(parent)
self.scrollDelagate = SmoothScrollDelegate(self)
class SingleDirectionScrollArea(QScrollArea):
""" Single direction scroll area"""
def __init__(self, parent=None, orient=Qt.Vertical):
"""
......@@ -21,6 +31,16 @@ class ScrollArea(QScrollArea):
"""
super().__init__(parent)
self.smoothScroll = SmoothScroll(self, orient)
self.vScrollBar = SmoothScrollBar(Qt.Vertical, self)
self.hScrollBar = SmoothScrollBar(Qt.Horizontal, self)
def setVerticalScrollBarPolicy(self, policy):
super().setVerticalScrollBarPolicy(policy)
self.vScrollBar.setForceHidden(policy == Qt.ScrollBarAlwaysOff)
def setHorizontalScrollBarPolicy(self, policy):
super().setHorizontalScrollBarPolicy(policy)
self.hScrollBar.setForceHidden(policy == Qt.ScrollBarAlwaysOff)
def setSmoothMode(self, mode):
""" set smooth mode
......@@ -37,97 +57,12 @@ class ScrollArea(QScrollArea):
e.setAccepted(True)
class SmoothScrollBar(QScrollBar):
""" Smooth scroll bar """
def __init__(self, parent=None):
QScrollBar.__init__(self, parent)
self.duration = 500
self.ani = QPropertyAnimation()
self.ani.setTargetObject(self)
self.ani.setPropertyName(b"value")
self.ani.setEasingCurve(QEasingCurve.OutCubic)
self.ani.setDuration(self.duration)
self.__value = self.value()
def setValue(self, value):
if value == self.value():
return
# stop running animation
self.ani.stop()
# adjust the duration
dv = abs(value - self.value())
if dv < 50:
self.ani.setDuration(int(self.duration * dv / 70))
else:
self.ani.setDuration(self.duration)
self.ani.setStartValue(self.value())
self.ani.setEndValue(value)
self.ani.start()
def scrollValue(self, value):
""" scroll the specified distance """
self.__value += value
self.__value = max(self.minimum(), self.__value)
self.__value = min(self.maximum(), self.__value)
self.setValue(self.__value)
def scrollTo(self, value):
""" scroll to the specified position """
self.__value = value
self.__value = max(self.minimum(), self.__value)
self.__value = min(self.maximum(), self.__value)
self.setValue(self.__value)
def resetValue(self, value):
self.__value = value
def mousePressEvent(self, e):
self.ani.stop()
super().mousePressEvent(e)
self.__value = self.value()
def mouseReleaseEvent(self, e):
self.ani.stop()
super().mouseReleaseEvent(e)
self.__value = self.value()
def mouseMoveEvent(self, e):
self.ani.stop()
super().mouseMoveEvent(e)
self.__value = self.value()
def setScrollAnimation(self, duration, easing=QEasingCurve.OutCubic):
""" set scroll animation
Parameters
----------
duration: int
scroll duration
easing: QEasingCurve
animation type
"""
self.duration = duration
self.ani.setDuration(duration)
self.ani.setEasingCurve(easing)
class SmoothScrollArea(QScrollArea):
""" Smooth scroll area """
def __init__(self, parent=None):
super().__init__(parent)
self.hScrollBar = SmoothScrollBar()
self.vScrollBar = SmoothScrollBar()
self.hScrollBar.setOrientation(Qt.Horizontal)
self.vScrollBar.setOrientation(Qt.Vertical)
self.setVerticalScrollBar(self.vScrollBar)
self.setHorizontalScrollBar(self.hScrollBar)
self.delegate = SmoothScrollDelegate(self, True)
def setScrollAnimation(self, orient, duration, easing=QEasingCurve.OutCubic):
""" set scroll animation
......@@ -143,13 +78,6 @@ class SmoothScrollArea(QScrollArea):
easing: QEasingCurve
animation type
"""
bar = self.hScrollBar if orient == Qt.Horizontal else self.vScrollBar
bar = self.delegate.hScrollBar if orient == Qt.Horizontal else self.delegate.vScrollBar
bar.setScrollAnimation(duration, easing)
def wheelEvent(self, e):
if e.modifiers() == Qt.NoModifier:
self.vScrollBar.scrollValue(-e.angleDelta().y())
else:
self.hScrollBar.scrollValue(-e.angleDelta().x())
e.setAccepted(True)
# coding:utf-8
from PyQt5.QtCore import (QEvent, QEasingCurve, Qt, pyqtSignal, QPropertyAnimation, pyqtProperty, QRectF,
QTimer, QPoint, QObject)
from PyQt5.QtGui import QPainter, QColor, QMouseEvent
from PyQt5.QtWidgets import (QWidget, QToolButton, QAbstractScrollArea, QGraphicsOpacityEffect,
QHBoxLayout, QVBoxLayout, QApplication)
from ...common.icon import FluentIcon
from ...common.style_sheet import isDarkTheme
from ...common.smooth_scroll import SmoothScroll
class ArrowButton(QToolButton):
""" Arrow button """
def __init__(self, icon: FluentIcon, parent=None):
super().__init__(parent=parent)
self.setFixedSize(10, 10)
self._icon = icon
def paintEvent(self, e):
painter = QPainter(self)
painter.setRenderHints(QPainter.Antialiasing)
s = 7 if self.isDown() else 8
x = (self.width() - s) / 2
self._icon.render(painter, QRectF(x, x, s, s), fill="#858789")
class ScrollBarGroove(QWidget):
""" Scroll bar groove """
def __init__(self, orient: Qt.Orientation, parent):
super().__init__(parent=parent)
if orient == Qt.Vertical:
self.setFixedWidth(12)
self.upButton = ArrowButton(FluentIcon.CARE_UP_SOLID, self)
self.downButton = ArrowButton(FluentIcon.CARE_DOWN_SOLID, self)
self.setLayout(QVBoxLayout(self))
self.layout().addWidget(self.upButton, 0, Qt.AlignHCenter)
self.layout().addStretch(1)
self.layout().addWidget(self.downButton, 0, Qt.AlignHCenter)
self.layout().setContentsMargins(0, 3, 0, 3)
else:
self.setFixedHeight(12)
self.upButton = ArrowButton(FluentIcon.CARE_LEFT_SOLID, self)
self.downButton = ArrowButton(FluentIcon.CARE_RIGHT_SOLID, self)
self.setLayout(QHBoxLayout(self))
self.layout().addWidget(self.upButton, 0, Qt.AlignVCenter)
self.layout().addStretch(1)
self.layout().addWidget(self.downButton, 0, Qt.AlignVCenter)
self.layout().setContentsMargins(3, 0, 3, 0)
self.opacityEffect = QGraphicsOpacityEffect(self)
self.opacityAni = QPropertyAnimation(self.opacityEffect, b'opacity', self)
self.setGraphicsEffect(self.opacityEffect)
self.opacityEffect.setOpacity(0)
def fadeIn(self):
self.opacityAni.setEndValue(1)
self.opacityAni.setDuration(150)
self.opacityAni.start()
def fadeOut(self):
self.opacityAni.setEndValue(0)
self.opacityAni.setDuration(150)
self.opacityAni.start()
def paintEvent(self, e):
painter = QPainter(self)
painter.setRenderHints(QPainter.Antialiasing)
painter.setPen(Qt.NoPen)
if not isDarkTheme():
painter.setBrush(QColor(252, 252, 252, 217))
else:
painter.setBrush(QColor(44, 44, 44, 245))
painter.drawRoundedRect(self.rect(), 6, 6)
class ScrollBarHandle(QWidget):
""" Scroll bar handle """
def __init__(self, orient: Qt.Orientation, parent=None):
super().__init__(parent)
self.orient = orient
if orient == Qt.Vertical:
self.setFixedWidth(3)
else:
self.setFixedHeight(3)
def paintEvent(self, e):
painter = QPainter(self)
painter.setRenderHints(QPainter.Antialiasing)
painter.setPen(Qt.NoPen)
r = self.width() / 2 if self.orient == Qt.Vertical else self.height() / 2
c = QColor(255, 255, 255, 139) if isDarkTheme() else QColor(0, 0, 0, 114)
painter.setBrush(c)
painter.drawRoundedRect(self.rect(), r, r)
class ScrollBar(QWidget):
""" Fluent scroll bar """
rangeChanged = pyqtSignal(tuple)
valueChanged = pyqtSignal(int)
sliderPressed = pyqtSignal()
sliderReleased = pyqtSignal()
sliderMoved = pyqtSignal()
def __init__(self, orient: Qt.Orientation, parent: QAbstractScrollArea):
super().__init__(parent)
self.groove = ScrollBarGroove(orient, self)
self.handle = ScrollBarHandle(orient, self)
self.timer = QTimer(self)
self._orientation = orient
self._singleStep = 1
self._pageStep = 50
self._padding = 14
self._minimum = 0
self._maximum = 0
self._value = 0
self._isPressed = False
self._isEnter = False
self._isExpanded = False
self._pressedPos = QPoint()
self._isForceHidden = False
if orient == Qt.Vertical:
self.partnerBar = parent.verticalScrollBar()
QAbstractScrollArea.setVerticalScrollBarPolicy(parent, Qt.ScrollBarAlwaysOff)
else:
self.partnerBar = parent.horizontalScrollBar()
QAbstractScrollArea.setHorizontalScrollBarPolicy(parent, Qt.ScrollBarAlwaysOff)
self.__initWidget(parent)
def __initWidget(self, parent):
self.groove.upButton.clicked.connect(self._onPageUp)
self.groove.downButton.clicked.connect(self._onPageDown)
self.groove.opacityAni.valueChanged.connect(self._onOpacityAniValueChanged)
self.partnerBar.rangeChanged.connect(self.setRange)
self.partnerBar.valueChanged.connect(self._onValueChanged)
self.valueChanged.connect(self.partnerBar.setValue)
parent.installEventFilter(self)
self.setRange(self.partnerBar.minimum(), self.partnerBar.maximum())
self.setVisible(self.maximum() > 0 and not self._isForceHidden)
def _onPageUp(self):
self.setValue(self.value() - self.pageStep())
def _onPageDown(self):
self.setValue(self.value() + self.pageStep())
def _onValueChanged(self, value):
self.val = value
def value(self):
return self._value
@pyqtProperty(int, notify=valueChanged)
def val(self):
return self._value
@val.setter
def val(self, value: int):
if value == self.value():
return
value = max(self.minimum(), min(value, self.maximum()))
self._value = value
self.valueChanged.emit(value)
# adjust the position of handle
self._adjustHandlePos()
def minimum(self):
return self._minimum
def maximum(self):
return self._maximum
def orientation(self):
return self._orientation
def pageStep(self):
return self._pageStep
def singleStep(self):
return self._singleStep
def isSliderDown(self):
return self._isPressed
def setValue(self, value: int):
self.val = value
def setMinimum(self, min: int):
if min == self.minimum():
return
self._minimum = min
self.rangeChanged.emit((min, self.maximum()))
def setMaximum(self, max: int):
if max == self.maximum():
return
self._maximum = max
self.rangeChanged.emit((self.minimum(), max))
def setRange(self, min: int, max: int):
if min > max or (min == self.minimum() and max == self.maximum()):
return
self.setMinimum(min)
self.setMaximum(max)
self._adjustHandleSize()
self._adjustHandlePos()
self.setVisible(max > 0 and not self._isForceHidden)
self.rangeChanged.emit((min, max))
def setPageStep(self, step: int):
if step >= 1:
self._pageStep = step
def setSingleStep(self, step: int):
if step >= 1:
self._singleStep = step
def setSliderDown(self, isDown: bool):
self._isPressed = True
if isDown:
self.sliderPressed.emit()
else:
self.sliderReleased.emit()
def expand(self):
""" expand scroll bar """
if self._isExpanded or not self.isEnter:
return
self._isExpanded = True
self.groove.fadeIn()
def collapse(self):
""" collapse scroll bar """
if not self._isExpanded or self.isEnter:
return
self._isExpanded = False
self.groove.fadeOut()
def enterEvent(self, e):
self.isEnter = True
self.timer.stop()
self.timer.singleShot(200, self.expand)
def leaveEvent(self, e):
self.isEnter = False
self.timer.stop()
self.timer.singleShot(200, self.collapse)
def eventFilter(self, obj, e: QEvent):
if obj is not self.parent():
return super().eventFilter(obj, e)
# adjust the position of slider
if e.type() == QEvent.Resize:
self._adjustPos(e.size())
return super().eventFilter(obj, e)
def resizeEvent(self, e):
self.groove.resize(self.size())
def mousePressEvent(self, e: QMouseEvent):
super().mousePressEvent(e)
self._isPressed = True
self._pressedPos = e.pos()
if self.childAt(e.pos()) is self.handle or not self._isSlideResion(e.pos()):
return
if self.orientation() == Qt.Vertical:
if e.pos().y() > self.handle.geometry().bottom():
value = e.pos().y() - self.handle.height() - self._padding
else:
value = e.pos().y() - self._padding
else:
if e.pos().x() > self.handle.geometry().right():
value = e.pos().x() - self.handle.width() - self._padding
else:
value = e.pos().x() - self._padding
self.setValue(int(value / self._slideLength() * self.maximum()))
self.sliderPressed.emit()
def mouseReleaseEvent(self, e):
super().mouseReleaseEvent(e)
self._isPressed = False
self.sliderReleased.emit()
def mouseMoveEvent(self, e: QMouseEvent):
if self.orientation() == Qt.Vertical:
dv = e.pos().y() - self._pressedPos.y()
else:
dv = e.pos().x() - self._pressedPos.x()
# don't use `self.setValue()`, because it could be reimplemented
dv = dv / self._slideLength() * (self.maximum() - self.minimum())
ScrollBar.setValue(self, self.value() + dv)
self._pressedPos = e.pos()
self.sliderMoved.emit()
def _adjustPos(self, size):
if self.orientation() == Qt.Vertical:
self.resize(12, size.height() - 2)
self.move(size.width() - 13, 1)
else:
self.resize(size.width() - 2, 12)
self.move(1, size.height() - 13)
def _adjustHandleSize(self):
total = self.maximum() - self.minimum() + self.parent().height()
if total != 0:
s = self._grooveLength() * self.parent().height() / total
else:
s = 1
if self.orientation() == Qt.Vertical:
self.handle.setFixedHeight(max(40, s))
else:
self.handle.setFixedWidth(max(40, s))
def _adjustHandlePos(self):
total = max(self.maximum() - self.minimum(), 1)
delta = self.value() / total * self._slideLength()
if self.orientation() == Qt.Vertical:
x = self.width() - self.handle.width() - 3
self.handle.move(x, self._padding + delta)
else:
y = self.height() - self.handle.height() - 3
self.handle.move(self._padding + delta, y)
def _grooveLength(self):
if self.orientation() == Qt.Vertical:
return self.height() - 2 * self._padding
return self.width() - 2 * self._padding
def _slideLength(self):
if self.orientation() == Qt.Vertical:
return self._grooveLength() - self.handle.height()
return self._grooveLength() - self.handle.width()
def _isSlideResion(self, pos: QPoint):
if self.orientation() == Qt.Vertical:
return self._padding <= pos.y() <= self.height() - self._padding
return self._padding <= pos.x() <= self.width() - self._padding
def _onOpacityAniValueChanged(self):
opacity = self.groove.opacityEffect.opacity()
if self.orientation() == Qt.Vertical:
self.handle.setFixedWidth(int(3 + opacity * 3))
else:
self.handle.setFixedHeight(int(3 + opacity * 3))
self._adjustHandlePos()
def setForceHidden(self, isHidden: bool):
""" whether to force the scrollbar to be hidden """
self._isForceHidden = isHidden
self.setVisible(self.maximum() > 0 and not isHidden)
def wheelEvent(self, e):
QApplication.sendEvent(self.parent().viewport(), e)
class SmoothScrollBar(ScrollBar):
""" Smooth scroll bar """
def __init__(self, orient: Qt.Orientation, parent):
super().__init__(orient, parent)
self.duration = 500
self.ani = QPropertyAnimation()
self.ani.setTargetObject(self)
self.ani.setPropertyName(b"val")
self.ani.setEasingCurve(QEasingCurve.OutCubic)
self.ani.setDuration(self.duration)
self.__value = self.value()
def setValue(self, value):
if value == self.value():
return
# stop running animation
self.ani.stop()
# adjust the duration
dv = abs(value - self.value())
if dv < 50:
self.ani.setDuration(int(self.duration * dv / 70))
else:
self.ani.setDuration(self.duration)
self.ani.setStartValue(self.value())
self.ani.setEndValue(value)
self.ani.start()
def scrollValue(self, value):
""" scroll the specified distance """
self.__value += value
self.__value = max(self.minimum(), self.__value)
self.__value = min(self.maximum(), self.__value)
self.setValue(self.__value)
def scrollTo(self, value):
""" scroll to the specified position """
self.__value = value
self.__value = max(self.minimum(), self.__value)
self.__value = min(self.maximum(), self.__value)
self.setValue(self.__value)
def resetValue(self, value):
self.__value = value
def mousePressEvent(self, e):
self.ani.stop()
super().mousePressEvent(e)
self.__value = self.value()
def mouseMoveEvent(self, e):
self.ani.stop()
super().mouseMoveEvent(e)
self.__value = self.value()
def setScrollAnimation(self, duration, easing=QEasingCurve.OutCubic):
""" set scroll animation
Parameters
----------
duration: int
scroll duration
easing: QEasingCurve
animation type
"""
self.duration = duration
self.ani.setDuration(duration)
self.ani.setEasingCurve(easing)
class SmoothScrollDelegate(QObject):
""" Smooth scroll delegate """
def __init__(self, parent: QAbstractScrollArea, useAni=False):
"""
Parameters
----------
parent: QAbstractScrollArea
the scrolling area being delegated
useAni: bool
whether to use `QPropertyAnimation` to achieve smooth scrolling
"""
super().__init__(parent)
self.useAni = useAni
self.vScrollBar = SmoothScrollBar(Qt.Vertical, parent)
self.hScrollBar = SmoothScrollBar(Qt.Horizontal, parent)
self.verticalSmoothScroll = SmoothScroll(parent, Qt.Vertical)
self.horizonSmoothScroll = SmoothScroll(parent, Qt.Horizontal)
parent.viewport().installEventFilter(self)
parent.setVerticalScrollBarPolicy = self.setVerticalScrollBarPolicy
parent.setHorizontalScrollBarPolicy = self.setHorizontalScrollBarPolicy
def eventFilter(self, obj, e: QEvent):
if e.type() == QEvent.Wheel:
if e.angleDelta().y() != 0:
if not self.useAni:
self.verticalSmoothScroll.wheelEvent(e)
else:
self.vScrollBar.scrollValue(-e.angleDelta().y())
else:
if not self.useAni:
self.horizonSmoothScroll.wheelEvent(e)
else:
self.hScrollBar.scrollValue(-e.angleDelta().x())
e.setAccepted(True)
return True
return super().eventFilter(obj, e)
def setVerticalScrollBarPolicy(self, policy):
QAbstractScrollArea.setVerticalScrollBarPolicy(self.parent(), policy)
self.vScrollBar.setForceHidden(policy == Qt.ScrollBarAlwaysOff)
def setHorizontalScrollBarPolicy(self, policy):
QAbstractScrollArea.setHorizontalScrollBarPolicy(self.parent(), policy)
self.hScrollBar.setForceHidden(policy == Qt.ScrollBarAlwaysOff)
......@@ -6,9 +6,9 @@ from PyQt5.QtGui import QPainter, QColor, QKeyEvent
from PyQt5.QtWidgets import (QStyledItemDelegate, QApplication, QStyleOptionViewItem,
QTableView, QTableWidget, QWidget)
from ...common.smooth_scroll import SmoothScroll
from ...common.style_sheet import isDarkTheme, FluentStyleSheet, themeColor
from .line_edit import LineEdit
from .scroll_bar import SmoothScrollDelegate
class TableItemDelegate(QStyledItemDelegate):
......@@ -126,8 +126,7 @@ class TableBase:
def __init__(self, *args, **kwargs):
self.delegate = TableItemDelegate(self)
self.verticalSmoothScroll = SmoothScroll(self, Qt.Vertical)
self.horizonSmoothScroll = SmoothScroll(self, Qt.Horizontal)
self.scrollDelagate = SmoothScrollDelegate(self)
# set style sheet
FluentStyleSheet.TABLE_VIEW.apply(self)
......@@ -170,14 +169,6 @@ class TableBase:
QTableView.resizeEvent(self, e)
self.viewport().update()
def wheelEvent(self, e):
if e.angleDelta().y() != 0:
self.verticalSmoothScroll.wheelEvent(e)
else:
self.horizonSmoothScroll.wheelEvent(e)
e.setAccepted(True)
def keyPressEvent(self, e: QKeyEvent):
QTableView.keyPressEvent(self, e)
self.setSelectedRows(self.selectedIndexes())
......@@ -190,7 +181,7 @@ class TableBase:
def mouseReleaseEvent(self, e):
QTableView.mouseReleaseEvent(self, e)
row = self.indexAt(e.pos()).row()
if row >= 0 and e.button() != Qt.RightButton:
self.setSelectedRows(self.selectedIndexes())
......
# coding:utf-8
from enum import Enum
from PyQt5.QtCore import QEvent, QSize, Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QToolButton
class ButtonState(Enum):
""" Button state """
NORMAL = 0
HOVER = 1
PRESSED = 2
class ThreeStateButton(QToolButton):
""" Three state tool button class """
def __init__(self, iconPaths, parent=None, buttonSize=(40, 40), iconSize=None):
"""
Parameters
----------
iconPaths: Dict[ButtonState, str]
icon path dict
parent:
parent window
button: tuple
button size
iconSize: tuple
icon size
"""
super().__init__(parent)
self.iconPaths = iconPaths
self.resize(*buttonSize)
self.setIconSize(self.size() if not iconSize else QSize(*iconSize))
self.setCursor(Qt.ArrowCursor)
self.setStyleSheet('border: none; margin: 0px; background: transparent')
self.setState(ButtonState.NORMAL)
self.installEventFilter(self)
def eventFilter(self, obj, e):
if obj is self:
if e.type() == QEvent.Enter:
self.setState(ButtonState.HOVER)
if e.type() in [QEvent.Leave, QEvent.MouseButtonRelease]:
self.setState(ButtonState.NORMAL)
if e.type() == QEvent.MouseButtonPress:
self.setState(ButtonState.PRESSED)
return super().eventFilter(obj, e)
def setState(self, state):
""" set the state of button """
self.setIcon(QIcon(self.iconPaths[state]))
\ No newline at end of file
# coding:utf-8
import typing
from PyQt5 import QtCore
from PyQt5.QtCore import Qt, QSize
from PyQt5.QtGui import QPainter, QColor
from PyQt5.QtWidgets import QWidget, QTreeWidget, QStyledItemDelegate, QStyle, QTreeView
from ...common.style_sheet import FluentStyleSheet, themeColor, isDarkTheme
from ...common.smooth_scroll import SmoothScroll
from .scroll_area import SmoothScrollDelegate
class TreeItemDelegate(QStyledItemDelegate):
......@@ -45,9 +44,8 @@ class TreeViewBase:
""" Tree view base class """
def __init__(self, *args, **kwargs):
self.verticalSmoothScroll = SmoothScroll(self, Qt.Vertical)
self.horizonSmoothScroll = SmoothScroll(self, Qt.Horizontal)
self.scrollDelagate = SmoothScrollDelegate(self)
self.setHorizontalScrollMode(QTreeView.ScrollPerPixel)
self.setVerticalScrollMode(QTreeView.ScrollPerPixel)
self.setItemDelegate(TreeItemDelegate(self))
......@@ -61,14 +59,6 @@ class TreeViewBase:
rect.moveLeft(15)
return QTreeView.drawBranches(self, painter, rect, index)
def wheelEvent(self, e):
if e.angleDelta().y() != 0:
self.verticalSmoothScroll.wheelEvent(e)
else:
self.horizonSmoothScroll.wheelEvent(e)
e.setAccepted(True)
class TreeWidget(QTreeWidget, TreeViewBase):
""" Tree widget """
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册