Home > Mobile >  how to set the QDockWidget Group color?
how to set the QDockWidget Group color?

Time:07-28

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!

NOTE: solved by myself, the answer link is enter image description here

CodePudding user response:

Maybe you can try widget->setStyleSheet(); but I suggest you can try setStyleSheet in qtdesigner,sametimes setStyleSheet() in cpp doesn't work。

CodePudding user response:

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()
  • Related