Im new to Qt and experimenting it.I have a layout whose code is given below:
MainWindow::MainWindow(QWidget *parent) :
QWidget(parent)
{
QVBoxLayout *parentLayout = new QVBoxLayout(this);//MainWindow is a QWidget
this->setStyleSheet("background-color:red");
for(int i=0;i<3;i++){
QHBoxLayout* labelLineEdit = f1();
parentLayout->addLayout(labelLineEdit);
}
parentLayout->setContentsMargins(0,0,40,0);
}
QHBoxLayout* MainWindow::f1()
{
QHBoxLayout *layout = new QHBoxLayout;
QLabel *label = new QLabel("Movie");
label->setStyleSheet("background-color:blue;color:white");
label->setMinimumWidth(300);
label->setMaximumWidth(300);
layout->addWidget(label);
QLineEdit *echoLineEdit = new QLineEdit;
//echoLineEdit->setMaximumWidth(120);//line:99
echoLineEdit->setMaximumHeight(50);
echoLineEdit->setMinimumHeight(50);
echoLineEdit->setStyleSheet("background-color:brown");
layout->addWidget(echoLineEdit);
layout->setSpacing(0);
return layout;
}
And my output looks like this.
I want my lineedit width to be reduced,so I uncommented the line 99 and my output looks like the below.
The setspacing and setContentsMargins attributes doesn't work in this case. Where am I going wrong.Anyhelp will be really useful.