Integration of laout into gridlayout

  • Hi ! So here is my two problems :) I have a Marblemap, a videostream and a pushbutton on my windows.
    I placed them in the gridlayout. However when I resize the window, only the video resize, my marblemap doesn't expand too. I dont have the problem when my program is launched without the camera linked (so I only have a blackscreeen instead of my video).

    I would like to have my map resized in proportion with the videoplayer inside my window :)

    Here is my main where I integrate all layouts :)

    #include <QApplication>
    #include <QWidget>
    #include "mafenetre.h"
    #include <marble/MarbleWidget.h>
    #include <QGridLayout>
    #include <QFont>
    #include <QSplitter>
    int main(int argc, char *argv[])
        QApplication app(argc, argv);
        // On crée le widget Marble via openstreet map
        Marble::MarbleWidget *mapWidget = new Marble::MarbleWidget;
        QWidget fenprincip;
        MaFenetre *video= new MaFenetre;//(&fenprincip); le =New MaFenetre est là pour déclarer video en tant que widget pour le layout
        // Création du Layout Grid :
        QGridLayout *layout = new QGridLayout;
        QPushButton *switch_bouton = new QPushButton("Switch");
        switch_bouton->setFont(QFont("Comic Sans MS", 14));
        // Création des boites layout
        /*QVBoxLayout *videolayout = new QVBoxLayout;
        QHBoxLayout *maplayout = new QHBoxLayout;
        QVBoxLayout *switchLayout = new QVBoxLayout;*/
        /*//On met les Widget dedans
        //Le redimensionnement auto ne marche pas sans trop de raison on va tenter avec une simple grille*/
       //On ajoute les widget à la grille
        layout->addWidget(video, 0,0,16,9);
        // Connexion du clic du bouton à la fermeture de l'application
        QObject::connect(switch_bouton, SIGNAL(clicked()), video, SLOT(quit()));
        return app.exec();

    Also my cpp file :

    #include "mafenetre.h"
    #include <QGraphicsScene>
    #include <QGraphicsView>
    #include <QGraphicsVideoItem>
    #include <QDebug>
    MaFenetre::MaFenetre(QWidget *parent) :
        //QString fichier = QCoreApplication::applicationDirPath() + QString("/test.mpg");
        qDebug() << QUrl("rtsp://");
        player = new QMediaPlayer;
        // GUI 1
        QVBoxLayout *layoutPrincipal = new QVBoxLayout;
        videoWidget = new QVideoWidget(this);
        connect(player, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(stateChanged(QMediaPlayer::State)));
        connect(player, SIGNAL(metaDataChanged()), this, SLOT(metaDataChanged()));
        connect(player, SIGNAL(metaDataChanged(const QString &, const QVariant &)), this, SLOT(metaDataChanged(const QString &, const QVariant &)));
        connect(player, SIGNAL(error(QMediaPlayer::Error)), this, SLOT(error(QMediaPlayer::Error)));
    void MaFenetre::stateChanged(QMediaPlayer::State state)
        qDebug() << Q_FUNC_INFO << state;
        if (state == QMediaPlayer::StoppedState)
    void MaFenetre::metaDataChanged()
        qDebug() << player->availableMetaData();
        if (player->isMetaDataAvailable())
            qDebug() << player->metaData(QMediaMetaData::Title).toString();
            qDebug() << player->metaData(QMediaMetaData::Size);
            qDebug() << player->metaData(QMediaMetaData::Duration);
            qDebug() << player->metaData(QMediaMetaData::Resolution);
    void MaFenetre::metaDataChanged(const QString &key, const QVariant &value)
        //"AudioBitRate", "AudioCodec", "PixelAspectRatio", "Resolution", "VideoCodec"
        if(key == "AudioCodec")
            qDebug() << key << value;
        if(key == "VideoCodec")
            qDebug() << key << value;
        if(key == "Resolution")
            qDebug() << key << value;
    void MaFenetre::error(QMediaPlayer::Error error)
        qDebug() << Q_FUNC_INFO << player->errorString() << error;

    Thanks for helping me :)

  • Lifetime Qt Champion


    From the looks of it, you are trying to set your grid layout on your MaFenetre object which already has a layout which should give you an error message.

  • @SGaist Thanks for your answer :)

    Oh sorry I forgot to delete the part (&fenprincip) (I modified my code but the problem is still here) :/

  • So I solved my problem by fixing all my coloumns with a setColumnSize :) Now everythings has the good place !

Log in to reply

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