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. QLayout setSpacing and setContentsMargin gives black color
Forum Update on Monday, May 27th 2025

QLayout setSpacing and setContentsMargin gives black color

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 306 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.
  • YunusY Offline
    YunusY Offline
    Yunus
    wrote on last edited by
    #1

    I am trying to use setSpacing and setContentsMargin for my QLayout.

    Both of these give a transparent view on Linux. However, these functions give a black border and space in Windows. I am wondering how can I use these functions on windows side transparently?

    Thanks

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Those two function should neither create a black nor a transparent space somewhere except you either use a custom QPalette or style sheets. So please provide a minimal, compilable example to reproduce your problem.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • YunusY Offline
        YunusY Offline
        Yunus
        wrote on last edited by
        #3

        @Christian-Ehrlicher Here is a simple code snippet I am using:

        QLayout* layout = this->layout();
        layout->setContentsMargins(10,10,10,10);
        QHBoxLayout* hBox = qobject_cast<QHBoxLayout*>(layout);
        hBox->addWidget(viewerWidget);
        

        The resulted window Margins are in black color on Windows, however on Linux they are transparent.

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The resulted window Margins are in black color on Windows, however on Linux they are transparent.

          This is not correct - they're in the background color which you somewhere changed (at least I would guess you do so). Please provide a fully, compilable example.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by Chris Kawa
            #5

            Layout is not a visual element, so it doesn't have color nor is it transparent. Whatever you see as black or transparent is the widget the layout is set on, so your example tells nothing.

            If you set your widget to be transparent via window flags it depends on the platform plugin and window manager if they implement that. On recent Windows you can't achieve transparent widgets (or at least the dedicated flags for it don't work anymore), and what you get is a black window background of the native window.

            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