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 reduce space between two different columns in Qt?
Forum Updated to NodeBB v4.3 + New Features

How to reduce space between two different columns in Qt?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 372 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.
  • P Offline
    P Offline
    patelvrajn
    wrote on last edited by patelvrajn
    #1

    Shown below is the code and an image of the GUI I am currently working on. As you will notice, there is an abundant amount of space between the two columns in the App_Grid (The green box which is not part of the GUI, represents the space I am talking about). I have tried my best to reduce this space to as little as possible but I cannot seem to reduce it any further. Can someone please help me reduce this space further by enlarging the text edit on the right of the buttons column? On a side note, I don't understand the concept of the stretch property, would someone be able to explain that as well. Thank you in advance for any help.

    0_1553758245274_Capture.PNG

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QtWidgets>
    #include <QtCore>
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        int win_dim_h = 520;
        int win_dim_w = 945;
        this->setMinimumSize(win_dim_w,win_dim_h);
        this->setMaximumSize(win_dim_w,win_dim_h);
    
        QGridLayout *App_Grid = new QGridLayout();
    
        QPushButton *Test_Button = new QPushButton("Test");
        QPushButton *Test_Button2 = new QPushButton("Test2");
        QPushButton *Test_Button3 = new QPushButton("Test3");
        QPushButton *Test_Button4 = new QPushButton("Test4");
        QTextEdit *Test_TextEdit = new QTextEdit();
    
        Test_Button->setMinimumHeight(25);
        Test_Button->setStyleSheet("background-color: white;");
        Test_Button2->setMinimumHeight(25);
        Test_Button2->setStyleSheet("background-color: white;");
        Test_Button3->setMinimumHeight(25);
        Test_Button3->setStyleSheet("background-color: white;");
        Test_Button4->setMinimumHeight(25);
        Test_Button4->setStyleSheet("background-color: white;");
    
        QVBoxLayout *Tabs_Grid = new QVBoxLayout();
        Tabs_Grid->addWidget(Test_Button,Qt::AlignHCenter);
        Tabs_Grid->addWidget(Test_Button2,Qt::AlignHCenter);
        Tabs_Grid->addWidget(Test_Button3,Qt::AlignHCenter);
        Tabs_Grid->addWidget(Test_Button4,Qt::AlignHCenter);
    
        float widget_screen_prop = 7/8;
    
        App_Grid->setSpacing(100);
        App_Grid->addLayout(Tabs_Grid,0,0,0);
        App_Grid->addWidget(Test_TextEdit,0,1,0);
        App_Grid->setColumnMinimumWidth(1,(widget_screen_prop)*this->width());
    
        QTextEdit *Logo = new QTextEdit();
        QTextEdit *Menu = new QTextEdit();
    
        QGridLayout *Menu_Grid = new QGridLayout();
        Menu_Grid-> setSpacing(25);
        Menu_Grid-> addLayout(App_Grid, 1, 0, 1,2, Qt::AlignCenter);
        Menu_Grid-> addWidget(Logo, 0, 0, 0);
        Menu_Grid-> addWidget(Menu, 0, 1, 0);
        Logo->setMinimumWidth(7*this->width()/8);
    
        QWidget *central = new QWidget(this);
        setCentralWidget(central);
        central->setLayout(Menu_Grid);
        central->setStyleSheet("background-color: white;");
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    
    jsulmJ 1 Reply Last reply
    0
    • P patelvrajn

      Shown below is the code and an image of the GUI I am currently working on. As you will notice, there is an abundant amount of space between the two columns in the App_Grid (The green box which is not part of the GUI, represents the space I am talking about). I have tried my best to reduce this space to as little as possible but I cannot seem to reduce it any further. Can someone please help me reduce this space further by enlarging the text edit on the right of the buttons column? On a side note, I don't understand the concept of the stretch property, would someone be able to explain that as well. Thank you in advance for any help.

      0_1553758245274_Capture.PNG

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include <QtWidgets>
      #include <QtCore>
      
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
          int win_dim_h = 520;
          int win_dim_w = 945;
          this->setMinimumSize(win_dim_w,win_dim_h);
          this->setMaximumSize(win_dim_w,win_dim_h);
      
          QGridLayout *App_Grid = new QGridLayout();
      
          QPushButton *Test_Button = new QPushButton("Test");
          QPushButton *Test_Button2 = new QPushButton("Test2");
          QPushButton *Test_Button3 = new QPushButton("Test3");
          QPushButton *Test_Button4 = new QPushButton("Test4");
          QTextEdit *Test_TextEdit = new QTextEdit();
      
          Test_Button->setMinimumHeight(25);
          Test_Button->setStyleSheet("background-color: white;");
          Test_Button2->setMinimumHeight(25);
          Test_Button2->setStyleSheet("background-color: white;");
          Test_Button3->setMinimumHeight(25);
          Test_Button3->setStyleSheet("background-color: white;");
          Test_Button4->setMinimumHeight(25);
          Test_Button4->setStyleSheet("background-color: white;");
      
          QVBoxLayout *Tabs_Grid = new QVBoxLayout();
          Tabs_Grid->addWidget(Test_Button,Qt::AlignHCenter);
          Tabs_Grid->addWidget(Test_Button2,Qt::AlignHCenter);
          Tabs_Grid->addWidget(Test_Button3,Qt::AlignHCenter);
          Tabs_Grid->addWidget(Test_Button4,Qt::AlignHCenter);
      
          float widget_screen_prop = 7/8;
      
          App_Grid->setSpacing(100);
          App_Grid->addLayout(Tabs_Grid,0,0,0);
          App_Grid->addWidget(Test_TextEdit,0,1,0);
          App_Grid->setColumnMinimumWidth(1,(widget_screen_prop)*this->width());
      
          QTextEdit *Logo = new QTextEdit();
          QTextEdit *Menu = new QTextEdit();
      
          QGridLayout *Menu_Grid = new QGridLayout();
          Menu_Grid-> setSpacing(25);
          Menu_Grid-> addLayout(App_Grid, 1, 0, 1,2, Qt::AlignCenter);
          Menu_Grid-> addWidget(Logo, 0, 0, 0);
          Menu_Grid-> addWidget(Menu, 0, 1, 0);
          Logo->setMinimumWidth(7*this->width()/8);
      
          QWidget *central = new QWidget(this);
          setCentralWidget(central);
          central->setLayout(Menu_Grid);
          central->setStyleSheet("background-color: white;");
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @patelvrajn said in How to reduce space between two different columns in Qt?:

      App_Grid->setSpacing(100);

      Did you try smaller spacing?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • P Offline
        P Offline
        patelvrajn
        wrote on last edited by patelvrajn
        #3

        I missed that line of code -____- , thank you for pointing that out, it fixed the issue.

        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