Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Change to Vertical Layout



  • Hi,

    I'm having problems with the layouts. I premade horizontal layout with the designer and have two widgets when the program starts. The 3rd added widget needs to be horizontal as well but the 4th one has to be vertically. I tried using QVBoxLayout but the widget didn't show up for some reason.


  • Qt Champions 2019

    @tactical77 You should show your code, so others can see what exactly you did.
    Also, you can use nested layouts: first QVBoxLayout, in it you put QHBoxLayout for horizontal widgets and you put the 4th widget directly into QVBoxLayout.



  • @jsulm

    Here's the method.

    void MainWindow::on_tableWidget_cellDoubleClicked(int row, int column)
    {
    
        //item in qstring speichern dann in std string konvertieren
    
        //datum in qstring abspeichern
        QString von = QString::fromStdString(t.getAllBookings(row)->getFromDate());
        QString bis = QString::fromStdString(t.getAllBookings(row)->getToDate());
    
    
    
        //qcalenderwidget objekt wird erstellt
        QCalendarWidget *cal = new QCalendarWidget(this);
    
        //datum wird markiert
        cal->setSelectedDate(QDate::fromString(von, "yyyyMMdd"));
    
    
        //objekt wird dem fenster horizontal hinzugefuegt
        ui->horizontalLayout->addWidget(cal);
    
    
        //zweiter kalender mit end datum
        QCalendarWidget *cal2 = new QCalendarWidget(this);
    
    
        //datum wird markiert
        cal2->setSelectedDate(QDate::fromString(bis, "yyyyMMdd"));
    
        QWidget *window = new QWidget;
        QVBoxLayout *layout = new QVBoxLayout;
        layout->addWidget(cal2);
        window->setLayout(layout);
        window->show();
    
    
    
        
    
    }
    
    

    The 4th widget appears as a new window but I need it to be down by the 3rd widget.


  • Qt Champions 2019

    @tactical77 What is the 4th widget? I only see 3 widgets here (cal, cal2, window).
    Also window widget does not have a parent and that's why it is shown as a window.
    And as I suggested before: use vertical layout and put there first the horizontal layout and then the 4th widget...


Log in to reply