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. QUiLoader - QVLayoutBox adjust Size
Forum Updated to NodeBB v4.3 + New Features

QUiLoader - QVLayoutBox adjust Size

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 823 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.
  • H Offline
    H Offline
    hcts
    wrote on last edited by
    #1

    I'm writing a program using Qt and C++ to reach the following result:

    a) vMain : main area - QVBoxLayout for the widget;

    b) hHeader: header area - QHBoxLayout to show two QLabels;

    c) vCenter: central area to host another widget loaded from ab ui file;

    @#include <QtGui\QApplication>
    #include <QtUiTools/QUiLoader>
    #include <QMenuBar>
    #include <QHBoxLayout>
    #include <QVBoxLayout>
    #include <QPushButton>
    #include <QLabel>
    #include <QFile>
    #include <QMessageBox>

    int main(int argc, char *argv[])
    {

    QApplication app(argc, argv);

    QWidget *window = new QWidget();
    
    
    //Create main layout
    
    QVBoxLayout *vMain = new QVBoxLayout();
    
    window->setLayout(vMain);
    
    
    //Create header layout
    
    QHBoxLayout *hHeader = new QHBoxLayout;
    
    vMain->addLayout(hHeader);
    
    hHeader->addWidget(new QLabel("User"));
    
    hHeader->addWidget(new QLabel("Module"));
    
    //Create central area
    
    QVBoxLayout *vCenter = new QVBoxLayout;
    
    vMain->addLayout(vCenter);
    
    
    //Create a widget from an ui file
    QUiLoader loader;
    QFile file&#40;"c:\\Logon.ui"&#41;;
    file.open(QFile::ReadOnly);
    QWidget *myWidget = loader.load(&file, window);
    file.close();
    
    vCenter->addWidget(myWidget);
    
    window->adjustSize();
    window->show();
    
    return app.exec();
    

    }@
    But the problem is that the main widget does not resize according the widget loaded from file.

    Does anybody have any about what is incorrect in this code?

    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