PDA

View Full Version : Constructing QWidget in QWidget



highlightsong
5th August 2008, 02:16
I'm trying to play MPlayer in QWidget.


#include "moviemainwindow.h"

#include <qvariant.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qaction.h>
#include <qmenubar.h>
#include <qpopupmenu.h>
#include <qtoolbar.h>
#include <qpoint.h>

/*
* Constructs a MovieMainWindow as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
*/
MovieMainWindow::MovieMainWindow( QWidget* parent, const char* name, WFlags fl )
: QWidget( parent, name, fl )
{
// (void)statusBar();
if ( !name )
setName( "MovieMainWindow" );

//Part for Constucting inner QWidget(screen).
this->screen = new ScreenMainWindow(this, "", WStyle_Customize|WStyle_NormalBorder);
this->screen->move( QPoint(0, 0) );
this->screen->show();

//Constructing PushButtons
this->playBtn = new QPushButton("play", this);
this->playBtn->setGeometry( 60, 180, 40, 30 );

this->pauseBtn = new QPushButton("pause", this);
this->pauseBtn->setGeometry( 100, 180, 40, 30 );

this->stopBtn = new QPushButton("stop", this);
this->stopBtn->setGeometry( 140, 180, 40, 30);

//SIGNAL and SLOT
QObject::connect(playBtn, SIGNAL(clicked()), this, SLOT(play()));
QObject::connect(pauseBtn, SIGNAL(clicked()), this, SLOT(pause()));
QObject::connect(stopBtn, SIGNAL(clicked()), this, SLOT(stop()));

languageChange();
resize( QSize(240, 210).expandedTo(minimumSizeHint()) );
clearWState( WState_Polished );

}

/*
* Destroys the object and frees any allocated resources
*/
MovieMainWindow::~MovieMainWindow()
{
// no need to delete child widgets, Qt does it all for us
}

/*
* Sets the strings of the subwidgets using the current
* language.
*/
void MovieMainWindow::languageChange()
{
setCaption( tr( "Movie" ) );
}

//Part for play
void MovieMainWindow::play()
{
this->proc1 = new QProcess(this);
this->proc1->addArgument( "mplayer" );
this->proc1->addArgument( "-slave" );
this->proc1->addArgument( "-identify" );
this->proc1->addArgument( "-quiet" );
this->proc1->addArgument( "-wid" );
this->proc1->addArgument( this->WID.setNum((int)(this->screen->winId())) );
this->proc1->addArgument( "/MPlayer/MPlayer-1.0pre8/[P]test.avi" );
this->proc1->start();
}

//Part for pause
void MovieMainWindow::pause()
{
this->proc1->writeToStdin( "pause\n" );
}

//Part for stop/quit
void MovieMainWindow::stop()
{
this->proc1->writeToStdin( "quit\n" );
}

I succeeded to control MPlayer by using QProcess.
My problem is when I clicked "play" button,
I intended to play MPlayer in inner QWidget(screen).
but when I did, MPlayer was played center of monitor.
To do that I intended, what should I do?? Help me plz......

spirit
5th August 2008, 08:49
you run an another application, so you can't insert this widget in your own app.

highlightsong
5th August 2008, 10:09
Sorry, but I cannot understand your opinion. Plz explain to me in detail.

spirit
5th August 2008, 10:17
when you run another programm using QProcess you currently create a new process and your own programm has own process, so you can't inject window from another process to your own process.
maybe you should use ActiveQt http://doc.trolltech.com/4.4/activeqt.html#activeqt for this purpose.