Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Stylesheet: using background image for floating DockWidgets
Forum Updated to NodeBB v4.3 + New Features

Stylesheet: using background image for floating DockWidgets

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.2k Views 1 Watching
  • 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.
  • MegamouseM Offline
    MegamouseM Offline
    Megamouse
    wrote on last edited by
    #1

    Hi,

    we use following code in our stylesheet to change the background of dockwidgets whenever they are attached/detached:

    QDockWidget {
    	background: transparent;
    }
    [floating="true"] {
    	background: #b3ac98;
    }
    

    The parent uses a border-image, therefore we have the dockwidgets use a transparent background.
    We would like to use the same image for the floating/detached dockwidgets as well but they just end up being all black.

    Is there any regular way to achieve this?
    I've seen this: https://stackoverflow.com/questions/10272091/cannot-add-a-background-image-to-a-qdockwidget
    but I am not sure if there's a simpler proper way.

    Thx, Megamouse

    1 Reply Last reply
    0
    • MegamouseM Offline
      MegamouseM Offline
      Megamouse
      wrote on last edited by
      #2

      I noticed that the dockwidgets are missing the title when using the stackoverflow method.

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        Yes if you draw it like
        style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
        then yes. its drawn as plan widget, not a dock :)

        1 Reply Last reply
        1
        • MegamouseM Offline
          MegamouseM Offline
          Megamouse
          wrote on last edited by
          #4

          I think I will try using that if floating== true.
          Else I'll use the native paintEvent. I will update when I'm done

          1 Reply Last reply
          0
          • MegamouseM Offline
            MegamouseM Offline
            Megamouse
            wrote on last edited by Megamouse
            #5

            It works perfectly with the method I just explained.
            Here the code for anybody interested: (partly taken from original post's source)

            void paintEvent(QPaintEvent* event)
            {
            	if (isFloating())
            	{
            		QStyleOption opt;
            		opt.init(this);
            		QPainter p(this);
            		style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
            		return;
            	}
            	QDockWidget::paintEvent(event);
            }
            

            in combination with:

            connect(this, &QDockWidget::topLevelChanged, [this](bool/* topLevel*/)
            {
            	style()->unpolish(this);
            	style()->polish(this);
            });
            
            H 1 Reply Last reply
            1
            • MegamouseM Megamouse

              It works perfectly with the method I just explained.
              Here the code for anybody interested: (partly taken from original post's source)

              void paintEvent(QPaintEvent* event)
              {
              	if (isFloating())
              	{
              		QStyleOption opt;
              		opt.init(this);
              		QPainter p(this);
              		style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
              		return;
              	}
              	QDockWidget::paintEvent(event);
              }
              

              in combination with:

              connect(this, &QDockWidget::topLevelChanged, [this](bool/* topLevel*/)
              {
              	style()->unpolish(this);
              	style()->polish(this);
              });
              
              H Offline
              H Offline
              HardikB
              wrote on last edited by
              #6

              @Megamouse I think QDockWidget::topLevelChanged() is not emitted when setting Floating property using QDockWidget::setFloating() method. As per the documentation, it should. Is anybody else getting this problem?

              1 Reply Last reply
              0

              • Login

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