Mainwindow is empty without any widgets.



  • When i build and run, the mainwindow is empty without any widgets.
    But i have created all the component in the mainwindow constructor.
    why they never appear?
    @
    -----------------MainWindow constructor------------
    ui->setupUi(this);
    brightnessLabel= new QLabel(tr("Brightness :"));
    brightnessName= new QLineEdit;
    brightnessLabel->setBuddy(brightnessName);

    contrastLabel= new QLabel(tr("Brightness :"));
    contrastName= new QLineEdit;
    contrastLabel->setBuddy(contrastName);
    
    volumeLabel= new QLabel(tr("Brightness :"));
    volumeName= new QLineEdit;
    volumeLabel->setBuddy(volumeName);
    
    OutputsourceLabel= new QLabel(tr("Brightness :"));
    OutputsourceName= new QLineEdit;
    OutputsourceLabel->setBuddy(OutputsourceName);
    
    DownloadLabel= new QLabel(tr("Brightness :"));
    DownloadName= new QLineEdit;
    DownloadLabel->setBuddy(DownloadName);
    
    QHBoxLayout *layout =new QHBoxLayout;
    layout->addWidget(brightnessLabel);
    layout->addWidget(brightnessName);
    

    ----------------------main------------------------
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    @



  • You have not assigned the layout to MainWindow.



  • How to assign ?



  • QMainWindow inherits a setlayout function.

    http://doc.qt.io/qt-5/qwidget.html#setLayout


  • Lifetime Qt Champion

    Hi,

    You can't change the layout of a QMainWindow. What you would do is create a main/container widget and set it as central widget.


Log in to reply
 

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