5yutan5 / PyQtDarkTheme

A flat dark theme for PySide and PyQt.
https://pyqtdarktheme.readthedocs.io
MIT License
545 stars 84 forks source link

Setting a theme enables mouseTracking in QTabBar #232

Open ptsavol opened 1 year ago

ptsavol commented 1 year ago

Windows 10, Python 3.11, PySide 6.4.1, pyqtdarktheme 2.1.0

Problem: Enabling a theme with qdarktheme.setup_theme() enables mouseTracking for QTabBars.

Steps to reproduce:

  1. Run the example app below
  2. Hover mouse over the tabs (label1 or label2) and you will see a bunch of prints MoveEvent mouseTracking:True
  3. Close the example app
  4. Comment line `qdarktheme.setup_theme()
  5. Run the example app again
  6. Hover mouse over the tabs and no prints appear
  7. Click on tab label1 or label2 and a print appears PressEvent mouseTracking:False

Expected behaviour: Mouse tracking in QTabBar should be disabled when a theme is enabled.

Here's the example app.

import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QTabWidget, QTabBar, QVBoxLayout, QWidget, QLabel
import qdarktheme

class MainWindow(QMainWindow):

    def __init__(self):
        super().__init__()
        self.setFixedSize(400, 300)
        tab_widget = QTabWidget(self)
        tab_bar = CustomTabBar(self)
        tab_widget.setTabBar(tab_bar)
        push_button = QPushButton("PyQtDarkTheme!!")
        tab1 = QLabel("abc")
        tab2 = QLabel("def")
        tab_widget.addTab(tab1, "label1")
        tab_widget.addTab(tab2, "label2")
        self.layout = QVBoxLayout()
        self.layout.addWidget(tab_widget)
        self.layout.addWidget(push_button)
        self.container = QWidget()
        self.container.setLayout(self.layout)
        self.setCentralWidget(self.container)

class CustomTabBar(QTabBar):
    def __init__(self, parent):
        super().__init__(parent)

    def mousePressEvent(self, event):
        print(f"PressEvent mouseTracking:{self.hasMouseTracking()}")
        super().mousePressEvent(event)

    def mouseMoveEvent(self, event):
        print(f"MoveEvent mouseTracking:{self.hasMouseTracking()}")
        super().mouseMoveEvent(event)

app = QApplication(sys.argv)
window = MainWindow()
window.show()
# Apply dark theme.
qdarktheme.setup_theme()  # Comment this line
app.exec()