Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to change the background color of a DockLabel instance??

How to change the background color of a DockLabel instance??

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 156 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bea1999
    wrote on 7 Apr 2025, 13:39 last edited by
    #1

    Hello, i tried to change the background color of DockLabel (class from anaconda package) using
    self.ImageDock.label.setStyleSheet("background-color: #04B2E2; color: white;")
    the default color is purple : #66c and i wanna change it to blue #04B2E2
    BUT IT DIDNT WORK!
    changing it from the actual package works but i dont wanna modify the class directly.
    Any idea how can i do that dynamically??
    Here's a minimal runnable script that shows this issue

    from PyQt5.QtWidgets import QApplication, QMainWindow
    from pyqtgraph.dockarea import Dock, DockArea
    import pyqtgraph as pg
    import sys
    
    class DockApp(QMainWindow):
        def __init__(self):
            super().__init__()
            self.setWindowTitle("Dockable Display App")
            self.setGeometry(100, 100, 800, 600)
            
            self.area = DockArea()
            self.setCentralWidget(self.area)
            
            self.set_dock_default()
    
        def set_dock_default(self):
            """Sets up the dock with a display window."""
            self.image_dock = Dock(name="Display Dock", size=(1, 1))
            self.image_dock.label.setStyleSheet("background-color: #04B2E2;") #change to blue but doesn't work, it still shows as purple
            self.display_window = pg.PlotWidget(title="Image Display")
            self.display_window.getViewBox().invertY(True)  # Inverting Y axis
            
            self.image_dock.addWidget(self.display_window)
            self.area.addDock(self.image_dock, "top")
    
    if __name__ == "__main__":
        app = QApplication(sys.argv)
        window = DockApp()
        window.show()
        sys.exit(app.exec_())
    
    
    J 1 Reply Last reply 7 Apr 2025, 15:51
    0
    • B bea1999
      7 Apr 2025, 13:39

      Hello, i tried to change the background color of DockLabel (class from anaconda package) using
      self.ImageDock.label.setStyleSheet("background-color: #04B2E2; color: white;")
      the default color is purple : #66c and i wanna change it to blue #04B2E2
      BUT IT DIDNT WORK!
      changing it from the actual package works but i dont wanna modify the class directly.
      Any idea how can i do that dynamically??
      Here's a minimal runnable script that shows this issue

      from PyQt5.QtWidgets import QApplication, QMainWindow
      from pyqtgraph.dockarea import Dock, DockArea
      import pyqtgraph as pg
      import sys
      
      class DockApp(QMainWindow):
          def __init__(self):
              super().__init__()
              self.setWindowTitle("Dockable Display App")
              self.setGeometry(100, 100, 800, 600)
              
              self.area = DockArea()
              self.setCentralWidget(self.area)
              
              self.set_dock_default()
      
          def set_dock_default(self):
              """Sets up the dock with a display window."""
              self.image_dock = Dock(name="Display Dock", size=(1, 1))
              self.image_dock.label.setStyleSheet("background-color: #04B2E2;") #change to blue but doesn't work, it still shows as purple
              self.display_window = pg.PlotWidget(title="Image Display")
              self.display_window.getViewBox().invertY(True)  # Inverting Y axis
              
              self.image_dock.addWidget(self.display_window)
              self.area.addDock(self.image_dock, "top")
      
      if __name__ == "__main__":
          app = QApplication(sys.argv)
          window = DockApp()
          window.show()
          sys.exit(app.exec_())
      
      
      J Offline
      J Offline
      JonB
      wrote on 7 Apr 2025, 15:51 last edited by JonB 4 Jul 2025, 15:54
      #2

      @bea1999 said in How to change the background color of a DockLabel instance??:

      changing it from the actual package works but i dont wanna modify the class directly.

      What do you mean by this? If, say, you are inside Dock's class code and you can go self.label.setStyleSheet(...) and that works then I cannot see why self.image_dock.label.setStyleSheet(...) from the outside world would not work. Are you sure you are supposed to set its label, I don't even see the docs explain what that is from https://pyqtgraph.readthedocs.io/en/latest/api_reference/dockarea.html#pyqtgraph.dockarea.Dock.

      B 1 Reply Last reply 7 Apr 2025, 19:52
      0
      • B Offline
        B Offline
        bea1999
        wrote on 7 Apr 2025, 18:40 last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • J JonB
          7 Apr 2025, 15:51

          @bea1999 said in How to change the background color of a DockLabel instance??:

          changing it from the actual package works but i dont wanna modify the class directly.

          What do you mean by this? If, say, you are inside Dock's class code and you can go self.label.setStyleSheet(...) and that works then I cannot see why self.image_dock.label.setStyleSheet(...) from the outside world would not work. Are you sure you are supposed to set its label, I don't even see the docs explain what that is from https://pyqtgraph.readthedocs.io/en/latest/api_reference/dockarea.html#pyqtgraph.dockarea.Dock.

          B Offline
          B Offline
          bea1999
          wrote on 7 Apr 2025, 19:52 last edited by
          #4

          @JonB ignore what i said in that line because i can't do this, if you just copy and run the script above, you will notice how it doesn't work and the color does not change to blue, hence the problem

          1 Reply Last reply
          0

          1/4

          7 Apr 2025, 13:39

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved