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. SOLVED: Insert Layout into scrollArea
QtWS25 Last Chance

SOLVED: Insert Layout into scrollArea

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 961 Views
  • 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.
  • Q Offline
    Q Offline
    Qatto
    wrote on last edited by
    #1

    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

    Web/Desktop Developer

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      Qatto
      wrote on last edited by
      #2

      Sorry guys, it actually works, but am just having trouble using widget arrays.

      Web/Desktop Developer

      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