Hello,
I have been trying to code a Horizontal Layout of widgets into a scrollArea which I placed using the Qt Designer but I still can’t get the private slot: display() to display the Layout after the pushButton is clicked(). Below is the mainwindow.cpp file, the rest of the files are the default for a MainWindow project.
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QHBoxLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QRect>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(display()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::display()
{
QLineEdit *lineEdit = new QLineEdit;
QPushButton *button = new QPushButton("ok");
QHBoxLayout *Layout = new QHBoxLayout;
Layout->addWidget(lineEdit);
Layout->addWidget(button);
QRect rect(20, 20, 100, 100);
Layout->setGeometry(rect);
ui->scrollArea->widget()->setLayout(Layout);
}
Please help me complete the display() function.
Thanks in Advance
↧