-1

The picture bellow is a pyside6 application's capture, I move all QDockWidget into a single group, but the group's header's background has two different color. How to change them into a single color(qss or code)? Thanks very much!

Environment:

  • macos 11.6.5
  • python 3.9.12
  • pyside6 6.3.1

Reproduction Code:

# coding: utf-8

import sys
import platform

from PySide6.QtWidgets import QApplication, QMainWindow, QDockWidget, QTextEdit
from PySide6.QtCore import Qt, QSysInfo


def main():
    app: QApplication = QApplication(sys.argv)
    window = QMainWindow()
    dock1 = QDockWidget("dock1")
    dock2 = QDockWidget("dock2")
    for dock in [dock1, dock2]:
        dock.setFeatures(dock.DockWidgetFloatable | dock.DockWidgetMovable)
    window.addDockWidget(Qt.LeftDockWidgetArea, dock1)
    window.addDockWidget(Qt.RightDockWidgetArea, dock2)

    os_info = QTextEdit()
    os_info.setText(platform.version())
    dock1.setWidget(os_info)

    qt_info = QTextEdit()
    info = QSysInfo()
    qt_info.setText(f"{info.kernelVersion()}, {info.prettyProductName()}, {info.productVersion()}")
    dock2.setWidget(qt_info)

    window.show()
    app.exec()


if __name__ == '__main__':
    main()

enter image description here

musicamante
  • 41,230
  • 6
  • 33
  • 58
Color
  • 875
  • 9
  • 11
  • Have you tried `dockWidget->setStyleSheet("background-color:black;");` or `QPalette pal = QPalette();pal.setColor(QPalette::Window, Qt::black);dockWidget->setAutoFillBackground(true);dockWidget->setPalette(pal);`? – László Papp Jul 27 '22 at 17:34
  • @Color Do you mean that you're using *tabbed* docks? That screenshot is not very clear, can you provide a basic [mre] so that we can better understand what you're referring to? Also, what Qt version (major *and* minor) and OS are you using? – musicamante Jul 27 '22 at 18:52
  • @LászlóPapp That code only change the background of the dock widget, it doesn't change the dock group's header's color – Color Jul 28 '22 at 02:04
  • @musicamante Thanks for your instruction, I paste the minimal reproducible example now, I should provide the code earlier. – Color Jul 28 '22 at 02:06

1 Answers1

0

I have solve it with the signal method myself:

# coding: utf-8

import sys
import platform

from PySide6.QtWidgets import QApplication, QMainWindow, QDockWidget, QTextEdit, QTabBar
from PySide6.QtCore import Qt, QSysInfo


def main():
    app: QApplication = QApplication(sys.argv)
    window = QMainWindow()
    dock1 = QDockWidget("dock1")
    dock2 = QDockWidget("dock2")
    for dock in [dock1, dock2]:
        dock.setFeatures(dock.DockWidgetFloatable | dock.DockWidgetMovable)
    window.addDockWidget(Qt.LeftDockWidgetArea, dock1)
    window.addDockWidget(Qt.RightDockWidgetArea, dock2)

    os_info = QTextEdit()
    os_info.setText(platform.version())
    dock1.setWidget(os_info)

    qt_info = QTextEdit()
    info = QSysInfo()
    qt_info.setText(f"{info.kernelVersion()}, {info.prettyProductName()}, {info.productVersion()}")
    dock2.setWidget(qt_info)

    style = """
        QTabBar {
            background-color: #ff0000;
        }       
    """
    app.setStyleSheet(style)

    # force update theme on dock change
    for w in window.children():
        if isinstance(w, QDockWidget):
            w.dockLocationChanged.connect(lambda: app.setStyleSheet(style))

    window.show()
    app.exec()


if __name__ == '__main__':
    main()
Color
  • 875
  • 9
  • 11
  • I understand that this is a working "fix", but resetting the *whole* application stylesheet anytime the dock location is changed is quite demanding, because it potentially causes ***any*** widget to completely repaint itself. This seems a bug, I strongly suggest you to do some research in the Qt bug tracker and eventually do a report. – musicamante Jul 28 '22 at 15:27
  • I think the better way is to find the QTabBar widget and set the style. I'll report it, but I don't know whether this is a bug or my poor knowledge of Qt. Anyway, this "fix" is just enough for my small personal tool to work. – Color Jul 29 '22 at 03:34
  • Qt issue link: https://bugreports.qt.io/browse/PYSIDE-2014 – Color Jul 29 '22 at 03:44