Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    How to remove the margin between QWidgets in layout

    General and Desktop
    layout margin s
    3
    6
    3648
    Loading More Posts
    • 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.
    • D
      DDWW last edited by p3c0

      mainLayout->setContentsMargins(0,0,0,0);
      This can't remove the margin in the center.

      here is my code:

          QWidget* titleBar = new QWidget(this);
          QHBoxLayout*    hLayout = new QHBoxLayout();
          QLabel* mTitle = new QLabel("hgis");
          hLayout->addWidget(mTitle);
          hLayout->addStretch();
          titleBar->setLayout(hLayout);
          titleBar->setStyleSheet("background-color:blue;");
      
          //
          QMainWindow* coreWidget = new QMainWindow(this);
          coreWidget->menuBar()->addAction(new QAction(QString("test1"),this));
          coreWidget->setWindowFlags(Qt::FramelessWindowHint);
          coreWidget->setStyleSheet("background-color:black;margin: 0px;");
      
          //
          QVBoxLayout* mainLayout = new QVBoxLayout();
          mainLayout->addWidget(titleBar);
          mainLayout->addWidget(coreWidget);
          mainLayout->setContentsMargins(0,0,0,0);
      
          setLayout(mainLayout);
          setStyleSheet("background-color:red;");
      

      I want to remove the red line between QLabel and QMainwindow.

      p3c0 1 Reply Last reply Reply Quote 0
      • p3c0
        p3c0 Moderators @DDWW last edited by

        Hi @DDWW and Welcome,
        setSpacing for mainLayout to 0.

        157

        D 1 Reply Last reply Reply Quote 0
        • Chris Kawa
          Chris Kawa Moderators last edited by

          Margin is the space around the content. Item spacing is controlled like this:

          mainLayout->setSpacing(0);
          
          1 Reply Last reply Reply Quote 0
          • D
            DDWW last edited by

            3Q very mush.I have been troubled by this problem for a long time.

            1 Reply Last reply Reply Quote 0
            • D
              DDWW @p3c0 last edited by

              @p3c0
              And can I use qss to have a similar effect?

              p3c0 1 Reply Last reply Reply Quote 0
              • p3c0
                p3c0 Moderators @DDWW last edited by

                @DDWW Stylesheets cannot be applied to QLayouts. So no way doing that. But if you dont use layout then setting min-height for both widgets may work.

                157

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post