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
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