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. Why is space before first button?

Why is space before first button?

Scheduled Pinned Locked Moved Unsolved General and Desktop
layout margin
3 Posts 3 Posters 380 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.
  • A Offline
    A Offline
    AndrzejB
    wrote on last edited by
    #1

    I have
    alt text

    my code:

    groupBox1 = new QGroupBox();
        groupBox1->setAlignment(Qt::AlignLeft);
        QHBoxLayout *horizLayout1 = new QHBoxLayout;
        QPushButton *btn1 = new QPushButton;
        btn1->setContentsMargins(0,0,0,0);
        btn1->setMaximumWidth(30);
        QPushButton *btn2 = new QPushButton;
        btn2->setMaximumWidth(30);
        QPushButton *btn3 = new QPushButton;
        btn3->setMaximumWidth(30);
        horizLayout1->addWidget(btn1);
        horizLayout1->addWidget(btn2);
        horizLayout1->addWidget(btn3);
        horizLayout1->addWidget(new QLineEdit);
        horizLayout1->addWidget(new QLineEdit);
        horizLayout1->setSpacing(0);
        horizLayout1->setMargin(0);
        groupBox1->setLayout(horizLayout1);
    
        QSplitter *splitter = new QSplitter(Qt::Orientation::Horizontal);
        splitter->addWidget(new QTreeView);
        splitter->addWidget(new QListView);
    ..
    QVBoxLayout *mainLayout = new QVBoxLayout;
        mainLayout->addWidget(groupBox1);
        mainLayout->addWidget(splitter);
        mainLayout->setSpacing(0);
        setLayout(mainLayout);
    

    Margins=0, spacing=0 but in left, upper corner is space

    J.HilkJ 1 Reply Last reply
    0
    • A AndrzejB

      I have
      alt text

      my code:

      groupBox1 = new QGroupBox();
          groupBox1->setAlignment(Qt::AlignLeft);
          QHBoxLayout *horizLayout1 = new QHBoxLayout;
          QPushButton *btn1 = new QPushButton;
          btn1->setContentsMargins(0,0,0,0);
          btn1->setMaximumWidth(30);
          QPushButton *btn2 = new QPushButton;
          btn2->setMaximumWidth(30);
          QPushButton *btn3 = new QPushButton;
          btn3->setMaximumWidth(30);
          horizLayout1->addWidget(btn1);
          horizLayout1->addWidget(btn2);
          horizLayout1->addWidget(btn3);
          horizLayout1->addWidget(new QLineEdit);
          horizLayout1->addWidget(new QLineEdit);
          horizLayout1->setSpacing(0);
          horizLayout1->setMargin(0);
          groupBox1->setLayout(horizLayout1);
      
          QSplitter *splitter = new QSplitter(Qt::Orientation::Horizontal);
          splitter->addWidget(new QTreeView);
          splitter->addWidget(new QListView);
      ..
      QVBoxLayout *mainLayout = new QVBoxLayout;
          mainLayout->addWidget(groupBox1);
          mainLayout->addWidget(splitter);
          mainLayout->setSpacing(0);
          setLayout(mainLayout);
      

      Margins=0, spacing=0 but in left, upper corner is space

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @AndrzejB thats very strange, I can confirm it on 5.15.8 and macOS, when you change the first item to a QLineEdit, everything lays out correctly.

      I would consider this a bug (if no-one else has an idea/workaround) and would open a ticket over at https://bugreports.qt.io , if there isn't already one open for it.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by ChrisW67
        #3

        I do not see this on Qt 5.15.2 Linux (The code does not compile under 6.2.3).
        Screenshot_20220405_171355.png

        What I note though is:

        • The QGroupBox border is absent in your screen shot. Something you have styled out or a Mac thing maybe?
        • The example code does not try to set the QGroupBox contents margins. They will be non-zero (3 pixels left/right for me) but not, I expect, as large as the gap on your left. There is no content margin or space for a border on the right in your screen shot; I would have expected a gap.

        If you are not going to use the group box title but need the visible border you could substitute QFrame. If you need neither the group box title nor the border then you can add the horizontal layout directly to the vertical layout and do without the container widget.

        1 Reply Last reply
        2

        • Login

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