Integration of laout into gridlayout
Solved
General and Desktop
-
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; mapWidget->setProjection(Marble::Mercator); mapWidget->setMapThemeId("earth/openstreetmap/openstreetmap.dgml"); mapWidget->setWindowTitle("Test!"); QWidget fenprincip; //fenprincip.setFixedSize(1600,900); 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 videolayout->addWidget(video);//(x,y,hauteur,largeur) maplayout->addWidget(mapWidget); switchLayout->addWidget(m_bouton); mapWidget->sizePolicy(); //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); layout->addWidget(mapWidget,15,17,4,4); layout->addWidget(switch_bouton,14,17,1,4); // Connexion du clic du bouton à la fermeture de l'application QObject::connect(switch_bouton, SIGNAL(clicked()), video, SLOT(quit())); fenprincip.show(); return app.exec(); }
Also my cpp file :
#include "mafenetre.h" #include <QGraphicsScene> #include <QGraphicsView> #include <QGraphicsVideoItem> #include <QDebug> MaFenetre::MaFenetre(QWidget *parent) : QWidget(parent) { //QString fichier = QCoreApplication::applicationDirPath() + QString("/test.mpg"); qDebug() << QUrl("rtsp://ednded:sokzd@169.254.xxx.xx/axis-media/media.amp"); player = new QMediaPlayer; player->setMedia(QUrl("rtsp://ednded:sokzd@169.254.xxx.xx/axis-media/media.amp")); // GUI 1 QVBoxLayout *layoutPrincipal = new QVBoxLayout; videoWidget = new QVideoWidget(this); layoutPrincipal->addWidget(videoWidget); player->setVideoOutput(videoWidget); setLayout(layoutPrincipal); setWindowTitle(QString::fromUtf8("player")); //setFixedWidth(960); //setFixedHeight(540); 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))); player->play(); } MaFenetre::~MaFenetre() { } void MaFenetre::stateChanged(QMediaPlayer::State state) { qDebug() << Q_FUNC_INFO << state; if (state == QMediaPlayer::StoppedState) { videoWidget->update(); } } 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 :)
-
Hi,
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.