Make QMainWindow scrollable



  • hello everybody.
    I can't add scrollbar to my widget. I've tried everything, here is the latest version:
    @
    #include "mainwindow.h"

    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    {
    setFixedSize(640,640);

    addOrderButton = new QPushButton(QString::fromLocal8Bit("Добавить заказ"),this);
    connect(addOrderButton, SIGNAL(clicked()),this, SLOT(addOrder()));
    orders = new QVector<QWidget*>();
    layout = new QVBoxLayout;
    
    scrollArea = new QScrollArea;
    setCentralWidget(scrollArea);
    addOrder();
    layout->addWidget(addOrderButton);
    scrollArea->setLayout(layout);
    

    }

    MainWindow::~MainWindow()
    {

    }

    void MainWindow::addOrder()
    {
    orderWidget* w = new orderWidget(this);
    orders->append(w);
    layout->insertWidget(orders->count() - 1, w);
    }
    @

    Sorry for the stupid question but i really stuck with it. What am i doing wrong?



  • @layout->insertWidget(orders->count() - 1, w);@

    here:
    @orders->count() - 1 == -1@

    You should
    @layout->addWidget(addOrderButton);
    orders->append(addOrderButton);@



  • After i make orders->append(w); count() already can't be equal to 0.
    And even if it was so, i don't understand how your advise can solve my problem


Log in to reply
 

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