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. Make QMainWindow scrollable
Qt 6.11 is out! See what's new in the release blog

Make QMainWindow scrollable

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.0k Views 1 Watching
  • 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.
  • L Offline
    L Offline
    longWorm
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • N Offline
      N Offline
      noregister
      wrote on last edited by
      #2

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

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

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

      1 Reply Last reply
      0
      • L Offline
        L Offline
        longWorm
        wrote on last edited by
        #3

        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

        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