How to reduce space between two different columns in Qt?



  • 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;
    }
    
    

  • Qt Champions 2018

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

    App_Grid->setSpacing(100);

    Did you try smaller spacing?



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.