PDA

View Full Version : Need Help with Layouts



baluk
20th October 2010, 19:14
Hi,

I have trouble applying layout dynamically to my main window. i have some button widgets with layouts applied on main window now I have to add the video widget dynamically on the top of my button widgets. When I add the video widget, the layout is not applied properly to it so that I can't able to resize the video. I need some help in this issue. Here I am copying my code, Please go through it. I am also attaching my two images desired image and getting image.




#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QMainWindow>
#include <phonon/audiooutput.h>
#include <phonon/seekslider.h>
#include <phonon/mediaobject.h>
#include <phonon/volumeslider.h>
#include <phonon/backendcapabilities.h>
#include <phonon/VideoWidget>
#include <phonon/VideoPlayer>
#include <QSplitter>
#include <QUrl>
#include <QHBoxLayout>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();

protected:
void changeEvent(QEvent *e);

private:
Ui::MainWindow *ui;
Phonon::MediaObject *mediaObject;
Phonon::AudioOutput *audioOutput;


};

#endif // MAINWINDOW_H

// .CPP file

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->mediaObject = new Phonon::MediaObject(this);
this->audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory,this);

Phonon::createPath(mediaObject, audioOutput);
Phonon::VideoWidget *videoWidget = new Phonon::VideoWidget(this);
videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatio4_3 );

videoWidget->setGeometry(10,20,500,250);

Phonon::createPath(mediaObject, videoWidget);
QUrl url("C:\\Users\\Bala\\Music\\3.Idiots-Give.Me.Some.Sunshine.mkv");
mediaObject->setCurrentSource(url);
mediaObject->setTickInterval(1000);
connect(mediaObject, SIGNAL(finished()), mediaObject, SLOT(deleteLater()));
connect(ui->pause,SIGNAL(clicked()),mediaObject,SLOT(pause())) ;
connect(ui->play,SIGNAL(clicked()),mediaObject,SLOT(play()));
connect(ui->stop,SIGNAL(clicked()),mediaObject,SLOT(stop()));
Phonon::SeekSlider *slider = new Phonon::SeekSlider(this);
slider->setMediaObject(mediaObject);

slider->setGeometry(504,393,84,19);
slider->show();

QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(slider);
ui->splitter->setLayout(layout);

ui->verticalLayout->addWidget(videoWidget,0,Qt::AlignTop); // Adding video widget to vertical layout
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}





Thank You,

Baluk

marcvanriet
20th October 2010, 22:47
Hi,

You have to add several widgets to your vertical layout : both the video player and the frame with controls. The layout has to be applied to your entire dialog also, to make it stretch with the dialog.

It is helpful if you first create the form with Qt Designer. Then you can see the effects of the layout you apply.

You can use a 'frame' instead of the video player window. You can even promote the frame to the videowidget if you like, so you can do everthing in Qt Designer.

Best regards,
Marc

baluk
21st October 2010, 08:30
Thanks marcvanrie, It worked -:).