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 Updated to NodeBB v4.3 + New Features

QLayout setSpacing and setContentsMargin gives black color

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 313 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.
  • Y Offline
    Y Offline
    Yunus
    wrote on 15 Dec 2022, 17:35 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
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 15 Dec 2022, 17:59 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
      • Y Offline
        Y Offline
        Yunus
        wrote on 15 Dec 2022, 18:09 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
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 15 Dec 2022, 18:20 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
          • C Offline
            C Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on 15 Dec 2022, 18:22 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

            1/5

            15 Dec 2022, 17:35

            • Login

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