zhiyiYo / PyQt-Fluent-Widgets

A fluent design widgets library based on C++ Qt/PyQt/PySide. Make Qt Great Again.
https://qfluentwidgets.com
GNU General Public License v3.0
5.37k stars 517 forks source link

PySide6 QPdfView ScrollBar #946

Open antoinechauvn opened 4 weeks ago

antoinechauvn commented 4 weeks ago

Hello, I would like to be able to attach one of your scrollbars to a PDF display. Unfortunately the object doesn't seem to be compatible at the moment.

Do you have any implementation solutions? Thanks

class PdfWidget(QFrame):

    def __init__(self, pdf_path: str, parent=None):
        super().__init__(parent=parent)

        # Initialize the PDF view and document
        self.pdfView = QPdfView(self)
        self.pdfDocument = QPdfDocument(self)
        self.pdfDocument.load(pdf_path)
        self.pdfView.setDocument(self.pdfDocument)

        # Set layout and remove margins
        self.hBoxLayout = QHBoxLayout(self)
        self.hBoxLayout.setContentsMargins(0, 0, 0, 0)
        self.hBoxLayout.addWidget(self.pdfView)

        # Set object name and styling for background
        self.setObjectName('pdf-viewer')
        self.pdfView.setStyleSheet("background-color: transparent; border: none;")

        # Replace scrollbars with Fluent-Widgets scrollbars
        self.verticalScrollBar = ScrollBar(Qt.Vertical, self.pdfView)
        self.horizontalScrollBar = ScrollBar(Qt.Horizontal, self.pdfView)

        self.pdfView.setVerticalScrollBar(self.verticalScrollBar)
        self.pdfView.setHorizontalScrollBar(self.horizontalScrollBar)
self.pdfView.setVerticalScrollBar(self.verticalScrollBar)
TypeError: 'PySide6.QtWidgets.QAbstractScrollArea.setVerticalScrollBar' called with wrong argument types:
  PySide6.QtWidgets.QAbstractScrollArea.setVerticalScrollBar(ScrollBar)
Supported signatures:
  PySide6.QtWidgets.QAbstractScrollArea.setVerticalScrollBar(PySide6.QtWidgets.QScrollBar)

image

zhiyiYo commented 4 weeks ago

You can use SmoothScrollDelegate, check the source code of ScrollArea.

antoinechauvn commented 4 weeks ago

You can use SmoothScrollDelegate, check the source code of ScrollArea.

Could you provide a better example using SmoothScrollDelegate?

# coding:utf-8
import sys
from PySide6.QtCore import QEasingCurve, Qt
from PySide6.QtGui import QPixmap
from PySide6.QtWidgets import QApplication
from qfluentwidgets import SmoothScrollArea, PixmapLabel

class Demo(SmoothScrollArea):

    def __init__(self):
        super().__init__()
        self.label = PixmapLabel(self)
        self.label.setPixmap(QPixmap("resource/shoko.jpg"))

        # customize scroll animation
        self.setScrollAnimation(Qt.Vertical, 500, QEasingCurve.OutQuint)
        self.setScrollAnimation(Qt.Horizontal, 500, QEasingCurve.OutQuint)

        self.horizontalScrollBar().setValue(1900)
        self.setWidget(self.label)
        self.resize(960, 640)

        with open('resource/demo.qss', encoding='utf-8') as f:
            self.setStyleSheet(f.read())

if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = Demo()
    w.show()
    app.exec()
antoinechauvn commented 4 weeks ago

My discord: armantaa or armanta