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. Scroll area is smaller than Dialog
Forum Updated to NodeBB v4.3 + New Features

Scroll area is smaller than Dialog

Scheduled Pinned Locked Moved Solved General and Desktop
scrollareadialog
4 Posts 2 Posters 1.8k 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.
  • G Offline
    G Offline
    gabor53
    wrote on 20 Feb 2016, 15:22 last edited by
    #1

    Hi,
    I have the following code that works perfectly in MainWindow, but in Dialog the scroll area is much smaller, than the Dialg, and the widgets don't fit in the scroll area.

    #include "dialog.h"
    #include "ui_dialog.h"
    #include <QScrollArea>
    #include <QGridLayout>
    #include <QLabel>
    #include <QVBoxLayout>
    #include <QLineEdit>
    #include <QSpacerItem>
    
    Dialog::Dialog(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::Dialog)
    {
        ui->setupUi(this);
        QWidget *mainWidget = new QWidget(this);
    
        QLabel* title = new QLabel ;
          title->setText("Add a Friend To the Database");
          title->setAlignment(Qt::AlignCenter);
          QFont f( "Arial", 18, QFont::Bold);
          title->setFont( f);
    
        QScrollArea *scroll = new QScrollArea(mainWidget);
        scroll->setWidgetResizable (true);
        scroll->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
        scroll->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
    
        QLabel *spacer1 = new QLabel;
        spacer1->setText ("           ");
        QLabel *spacer2 = new QLabel;
        spacer2->setText ("                    ");
    
    
        QLabel *Name_Label = new QLabel;
        Name_Label->setText ("Name: ");
    
        QLabel *Address_Label = new QLabel;
        Address_Label->setText ("Address: ");
    
        QLineEdit *Name_Edit = new QLineEdit;
    
        Name_Edit->setMaxLength (10);
    
        QLineEdit *Address_Edit = new QLineEdit;
    
        Address_Edit->setMaxLength (10);
    
        QGridLayout *grid = new QGridLayout;
    
        QWidget *viewport = new QWidget(this);
        scroll->setWidget (viewport);
        scroll->setWidgetResizable (true);
    
        QHBoxLayout *Name_Layout = new QHBoxLayout;
        Name_Layout->addWidget (Name_Label);
        Name_Layout->addWidget (Name_Edit);
    
        grid->addWidget (Name_Label,0,0);
        grid->addWidget (Name_Edit,0,1);
        grid->addWidget (spacer2,0,1,Qt::AlignRight);
        grid->addWidget (spacer1,0,2);
        grid->addWidget (Address_Label,1,0);
        grid->addWidget (Address_Edit,1,1);
        grid->addWidget (spacer2,1,1,Qt::AlignRight);
        grid->addWidget (spacer1,1,2);
    
        scroll->setLayout (grid);
    
        QVBoxLayout *mainLayout = new QVBoxLayout(mainWidget);
        mainLayout->addWidget (title);
        mainLayout->addWidget (scroll);
    
    
        mainWidget->setLayout (mainLayout);
    
    
    }
    
    Dialog::~Dialog()
    {
        delete ui;
    }
    
    

    Dialog
    How can I change the code to make the scroll area stretch with the dialog (and cover the whole dialog)?
    Thank you.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 20 Feb 2016, 21:21 last edited by
      #2

      Hi,

      Since you seem to build your widget in the constructor, why do you a designer based base class ?

      What currently happens is that mainWidget is a child of Dialog and it's not managed by any layout so you would have to do the positioning and sizing yourself unless you remove the designer bits (since you don't seem to need them at all in this case) then you can simply remove mainWidget and set mainLayout on your dialog and you should be good to go.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • G Offline
        G Offline
        gabor53
        wrote on 20 Feb 2016, 23:36 last edited by
        #3

        Thanks. How can I remove the "designer bits"?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gabor53
          wrote on 21 Feb 2016, 03:58 last edited by
          #4

          I got it. Thank you for your help.

          1 Reply Last reply
          0

          1/4

          20 Feb 2016, 15:22

          • Login

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