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. How to use QSpacerItem?
Forum Updated to NodeBB v4.3 + New Features

How to use QSpacerItem?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.5k 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.
  • Q Offline
    Q Offline
    qwe3
    wrote on last edited by
    #1

    Hi,

    I have QGridLayout and three QLabels with textes in it.

    I would like to use spacer to move labels to down:

    nnn.png

    Now I have situation on the left and I would like to have situation on the right.

    I try something like this:

        grid = new QGridLayout;
        centralWidget()->setLayout(grid);
        l1 = new QLabel("random1");
        l2 = new QLabel("random2");
        l3 = new QLabel("random3");
        grid->addWidget(l1,0,1);
        grid->addWidget(l2,1,1);
        grid->addWidget(l3,2,1);
        QSpacerItem *spacerV1 = new QSpacerItem(1,1,QSizePolicy::Policy::Minimum,QSizePolicy::Policy::Maximum);
        grid->addItem(spacerV1,0,0,3,1);
    

    but with no effects.

    Pl45m4P 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi

      
          auto grid = new QGridLayout;
          centralWidget()->setLayout(grid);
          auto l1 = new QLabel("random1");
          auto  l2 = new QLabel("random2");
          auto l3 = new QLabel("random3");
          QSpacerItem *spacerV1 = new QSpacerItem(21, 41, QSizePolicy::Policy::Minimum,  QSizePolicy::Policy::Expanding);
          grid->addItem(spacerV1, 0, 0, 1, 1);
          grid->addWidget(l1, 1, 0);
          grid->addWidget(l2, 2, 0);
          grid->addWidget(l3, 3, 0);
      
      

      Not sure what was wrong. maybe the cols/rows

      alt text

      1 Reply Last reply
      1
      • Q qwe3

        Hi,

        I have QGridLayout and three QLabels with textes in it.

        I would like to use spacer to move labels to down:

        nnn.png

        Now I have situation on the left and I would like to have situation on the right.

        I try something like this:

            grid = new QGridLayout;
            centralWidget()->setLayout(grid);
            l1 = new QLabel("random1");
            l2 = new QLabel("random2");
            l3 = new QLabel("random3");
            grid->addWidget(l1,0,1);
            grid->addWidget(l2,1,1);
            grid->addWidget(l3,2,1);
            QSpacerItem *spacerV1 = new QSpacerItem(1,1,QSizePolicy::Policy::Minimum,QSizePolicy::Policy::Maximum);
            grid->addItem(spacerV1,0,0,3,1);
        

        but with no effects.

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by Pl45m4
        #3

        @qwe3 said in How to use QSpacerItem?:

        grid->addItem(spacerV1,0,0,3,1);

        Your spacer and your labels dont share the same column.
        Your items are in column 1, your spacer is in 0.

        void QGridLayout::addItem(QLayoutItem *item, int row, int column, int rowSpan = 1, int columnSpan = 1, Qt::Alignment alignment = Qt::Alignment())

        • https://doc.qt.io/qt-5/qgridlayout.html#addItem

        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        3

        • Login

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