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. QDockWidget default title not respecting setContentsMargins
Forum Updated to NodeBB v4.3 + New Features

QDockWidget default title not respecting setContentsMargins

Scheduled Pinned Locked Moved Unsolved General and Desktop
qdockwidgetmargins
5 Posts 3 Posters 3.0k Views 2 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.
  • E Offline
    E Offline
    Erika
    wrote on 24 Feb 2016, 19:00 last edited by
    #1

    I've discovered that if you call setContentsMargins on a dock widget, the default title bar remains left aligned and at the fixed width, leaving unusually awkward spacing to the left. If the dockwidget is floating, this is a non-issue, with margins added as expected, however I'm not sure of the best way to resolve this when docked.

    Simple example:

    #include <QtWidgets\QApplication>
    #include <QtWidgets\QMainWindow>
    #include <QtWidgets\QDockWidget>
    int main(int argc, char *argv[])
    { 	QApplication app(argc, argv);
    	app.setApplicationName("Dock Margins Example");
    	QMainWindow mainWin;
    
    	// setup widgets
    	QDockWidget exampleDock(&mainWin);
    	QWidget dockContents;
    
    	dockContents.setStyleSheet(QStringLiteral("background: #FFFFFF;")); // contents colouring
    	exampleDock.setWidget(&dockContents);
    	mainWin.addDockWidget(Qt::LeftDockWidgetArea, &exampleDock);
    	exampleDock.setWindowTitle("Example Dock");
    	exampleDock.setContentsMargins(30, 30, 30, 30);
    	
    	mainWin.show();
    	return app.exec();
    }
    

    Docked Issues:
    alt text
    Floating OK:
    alt text

    I've also noticed that the top margin appears ignored while docked (seems set as the same as title's height), but as-expected when floating.

    Any suggestions on how to resolve the offset title (without having to create a custom title widget), or is it a bug? I've tried a few style changes, but nothing successful so far.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 24 Feb 2016, 19:09 last edited by Chris Kawa
      #2

      Looks like a bug. You should report it. The content margins feature has quite a few glitches. I've seen similar problems in other circumstances. It's not a very often used feature so these problems probably get overlooked.

      As a workaround you can place a dummy widget and the real content inside it. You can then set the margins on the dummy or on its layout.

      E 1 Reply Last reply 24 Feb 2016, 20:54
      0
      • K Offline
        K Offline
        kshegunov
        Moderators
        wrote on 24 Feb 2016, 19:12 last edited by
        #3

        @Erika
        Instead of this:

        exampleDock.setContentsMargins(30, 30, 30, 30);
        

        You could try something along the lines of:

        exampleDock.layout()->setContentsMargins(30, 30, 30, 30);
        

        Although, I'm not quite sure it'll work.

        Kind regards.

        Read and abide by the Qt Code of Conduct

        E 1 Reply Last reply 24 Feb 2016, 20:29
        0
        • K kshegunov
          24 Feb 2016, 19:12

          @Erika
          Instead of this:

          exampleDock.setContentsMargins(30, 30, 30, 30);
          

          You could try something along the lines of:

          exampleDock.layout()->setContentsMargins(30, 30, 30, 30);
          

          Although, I'm not quite sure it'll work.

          Kind regards.

          E Offline
          E Offline
          Erika
          wrote on 24 Feb 2016, 20:29 last edited by
          #4

          @kshegunov Thanks. Unfortunately that doesn't have any impact.

          1 Reply Last reply
          0
          • C Chris Kawa
            24 Feb 2016, 19:09

            Looks like a bug. You should report it. The content margins feature has quite a few glitches. I've seen similar problems in other circumstances. It's not a very often used feature so these problems probably get overlooked.

            As a workaround you can place a dummy widget and the real content inside it. You can then set the margins on the dummy or on its layout.

            E Offline
            E Offline
            Erika
            wrote on 24 Feb 2016, 20:54 last edited by
            #5

            @Chris-Kawa Thanks. I agree it seems like a bug, and have now reported it: https://bugreports.qt.io/browse/QTBUG-51359. I figure the widget-inside-widget would be a workable alternative, but was hoping to avoid that route. C'est la vie.

            1 Reply Last reply
            0

            3/5

            24 Feb 2016, 19:12

            • Login

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