I am now able to align all the widgets one by one towards left



  • /* creating the refresh button/checkbox at the bottom widget*/
    QWidget bottomWidget = new QWidget;
    QHBoxLayout controlsLayout = new QHBoxLayout;
    QPushButton
    d_button = new QPushButton("Button1");
    QPushButton
    d_checkBox1 = new QCheckBox("CheckBox1");
    QPushButton* d_checkBox2 = new QCheckBox("CheckBox2");
    QPushButton* d_checkbox3 = new QCheckBox("CheckBox2");
    controlsLayout->addStretch(0);
    controlsLayout->addWidget(d_button);
    controlsLayout->addWidget(d_checkBox1);
    controlsLayout->addWidget(d_checkBox2);
    controlsLayout->addWidget(d_checkbox3;
    bottomWidget->setLayout(controlsLayout);

    d_checkBox1->setMaximumWidth(80);
    d_checkBox2->setMaximumWidth(130);
    d_checkBox3->setMaximumWidth(330);
    

    These buttons are not aligned one by one towards left , I get alignment at attached in the snapshot

    https://postimg.org/image/kjo8y43bd/6e8856bf/

    Could you please let me know how to apply the aligment



  • Not able to see the image. Nevertheless did try with setting alignment while for addwidget API ?



  • Yes I gave the the alignment as as 1 .
    What should I do to place all the buttons checkboxes one by one towards left alignment



  • @Qt-Enthusiast

    the picture is super tiny, so I don't know what your problem is exactly.

    But you can set the Alignment directly when you add the widgets to the QHBoxLayout

    addWidget has more than 1 argument, but the other have a default value if you dont specify them.

    controlsLayout->addStretch(0);
    controlsLayout->addWidget(d_button, 0,  Qt::AligntLeft);
    controlsLayout->addWidget(d_checkBox1,0,  Qt::AligntLeft);
    controlsLayout->addWidget(d_checkBox2,0,  Qt::AligntLeft);
    controlsLayout->addWidget(d_checkbox3,0,  Qt::AligntLeft);
    

    Does that help you?


Log in to reply
 

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