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.61k stars 541 forks source link

[Bug]: Using QWebEngineView() breaks PyQT-Fluent-Widgets Theme #581

Closed kamalexandre closed 1 year ago

kamalexandre commented 1 year ago

What happened?

When I try to add QWebEngineView(), the theme does not display correctly for both DARK and LIGHT.

If i remove the QWebEngineView(), then theme works as expected.

Operation System

Window 11

Python Version

3.11

PyQt/PySide Version

PySide6

PyQt/PySide-Fluent-Widgets Version

v1.3.2

How to Reproduce?

adding web view makes the theme break

Create a splitter and add QWebEngineView and table to it

    self.splitter = QSplitter(Qt.Horizontal)
    self.splitter.addWidget(self.webView)
    self.splitter.addWidget(self.table)

but if you comment the web view. theme works fine but then missing the webview

Create a splitter and remove QWebEngineView

    self.splitter = QSplitter(Qt.Horizontal)
    ##self.splitter.addWidget(self.webView)
    self.splitter.addWidget(self.table)

Minimum code

import sys
from PySide6.QtCore import Qt, QUrl
from PySide6.QtGui import QIcon, QDesktopServices
from PySide6.QtWidgets import QApplication, QFrame, QVBoxLayout, QSplitter, QWidget, QLabel, QHBoxLayout, QPushButton, \
    QTableWidgetItem, QLineEdit
from PySide6.QtWebEngineWidgets import QWebEngineView  # Add this import at the beginning
from qfluentwidgets import (NavigationItemPosition, MessageBox, setTheme, Theme, FluentWindow,
                            NavigationAvatarWidget, qrouter, SubtitleLabel, setFont, InfoBadge,
                            InfoBadgePosition,TableWidget,)
from qfluentwidgets import FluentIcon as FIF
import random

class test(QFrame):
    def __init__(self, parent=None):
        super().__init__(parent=parent)
        # Set objectName for the widget
        self.setObjectName("QWebEngineView_Test")

        self.layout = QVBoxLayout(self)

        # Create the QWebEngineView and load a URL (I'll use example.com as placeholder)
        self.webView = QWebEngineView()
        self.webView.load(QUrl("http://www.google.com"))

        # Table
        self.table = TableWidget(self)
        self.table.setRowCount(0)
        self.table.setColumnCount(6)
        self.table.setHorizontalHeaderLabels([
            "Column 1", "Column 2", "Column 3", "Column 4", "Column 5", "Column 6"
        ])

        # Add random rows
        self.add_random_rows(10)  # Add 10 random rows

        # Create a splitter and add QWebEngineView and table to it
        self.splitter = QSplitter(Qt.Horizontal)
        self.splitter.addWidget(self.webView)
        self.splitter.addWidget(self.table)

        # Add the splitter to the main layout
        self.layout.addWidget(self.splitter)

        # CommandBar and Buttons
        hBoxLayout = QHBoxLayout()
        self.commandBar = QLabel("CommandBar Placeholder", self)  # Placeholder
        hBoxLayout.addWidget(self.commandBar)
        self.layout.addLayout(hBoxLayout)

        # TODO: Add further components and logic

    # TODO: Implement other methods
    def add_random_rows(self, number_of_rows: int):
        data1 = ["data1_A", "data1_B", "data1_C", "data1_D", "data1_E"]
        data2 = ["data2_A", "data2_B", "data2_C"]
        data3 = ["data3_1", "data3_2", "data3_3"]
        data4 = ["data4_1", "data4_2", "data4_3"]  # Replace with actual paths

        for _ in range(number_of_rows):
            row_position = self.table.rowCount()
            self.table.insertRow(row_position)

            # Randomly select values for each column
            self.table.setItem(row_position, 0, QTableWidgetItem(random.choice(data1)))
            self.table.setItem(row_position, 1, QTableWidgetItem(str(random.randint(1, 500))))
            self.table.setItem(row_position, 2, QTableWidgetItem("Some random stuff"))
            self.table.setItem(row_position, 3, QTableWidgetItem(random.choice(data2)))
            self.table.setItem(row_position, 4, QTableWidgetItem(random.choice(data3)))
            self.table.setItem(row_position, 5, QTableWidgetItem(random.choice(data4)))

class MainWindow(FluentWindow):
    def __init__(self):
        super().__init__()

        # create sub interfaces
        self.test1 = test(self)

        self.initNavigation()
        self.initWindow()

    def initNavigation(self):
        self.addSubInterface(self.test1, FIF.DOCUMENT, 'QWebEngineView_Test')

    def initWindow(self):
        self.resize(900, 700)
        self.setWindowIcon(QIcon(':/qfluentwidgets/images/logo.png'))
        self.setWindowTitle('QWebEngineView_Test')

        desktop = QApplication.screens()[0].availableGeometry()
        w, h = desktop.width(), desktop.height()
        self.move(w // 2 - self.width() // 2, h // 2 - self.height() // 2)

if __name__ == '__main__':
    setTheme(Theme.LIGHT)

    app = QApplication(sys.argv)
    w = MainWindow()
    w.show()
    app.exec()
zhiyiYo commented 1 year ago

Dulplicated with https://github.com/zhiyiYo/PyQt-Frameless-Window/issues/126