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. Custom widget got squashed in scroll area
Forum Updated to NodeBB v4.3 + New Features

Custom widget got squashed in scroll area

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 725 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.
  • B Offline
    B Offline
    BadPistol97
    wrote on 28 Apr 2019, 16:39 last edited by
    #1

    I am trying to add custom widgets into a scroll area expecting the scroll bar will appear when widgets are getting many while the widgets remain its original size.

    this is my custom widget:
    0_1556468964511_1.PNG

    and this is the main window:
    0_1556469047487_2.PNG
    1_1556468987670_3.PNG

    The button in the main window adds a custom widget each click.
    When I try to click the button once:
    0_1556469143898_4.PNG

    Now I click the button for three times:
    0_1556469197431_5.PNG

    But it works when I add QPushButtons:
    0_1556469292215_6.PNG

    this is the code of mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <modal.h>
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        ui->scrollAreaWidgetContents->setLayout(ui->verticalLayout_3);
    
        ui->scrollArea->setWidgetResizable(true);
    
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::on_pushButton_clicked()
    {
    
        // add custom widget
        ui->scrollArea->widget()->layout()->addWidget(new modal(this));
    
        ui->scrollArea->ensureVisible(1000,1000);
    
        ui->scrollArea->ensureWidgetVisible(ui->scrollArea->widget()->layout()->widget());
    }
    
    

    I am new to QT, this got me puzzled for a weeks. Thanks in advance for the help

    1 Reply Last reply
    2
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 28 Apr 2019, 17:18 last edited by mrjj
      #2

      Hi and welcome to the forums
      Good post +1
      Its due to setMinimumSize that you can set on all Widgets.
      The CalenderWidget/customWidget has none set which means scroll areas layout is allowed to make them smaller and smaller
      when more is added.
      QPushbutton, on the other hand, has FixedSize for its height so they are not compressed. (made smaller)

      To fix it, you can simply set a minimum size/height for the calendar widget/its form

      modal * NewModal = new modal(this)
      NewModal ->setMinimumHeight(200); // wont become smaller than this then
       ui->scrollArea->widget()->layout()->addWidget(NewModal );
      

      QPushButton
      alt text

      compare that to the CalenderWidget/CustomWidget/the "modal" form

      1 Reply Last reply
      2
      • B Offline
        B Offline
        BadPistol97
        wrote on 28 Apr 2019, 23:32 last edited by
        #3

        It wooooooorrrrkkks !!! Thank you so much 💋

        1 Reply Last reply
        1

        1/3

        28 Apr 2019, 16:39

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved