Hi,
I used the same way to try to embedded a QX11EmbedContainer into QML but the result is not really good :
My goal is to use the QX11EmbedContainer to execute mplayer and to declare this one as a QML Element to be able to manipulate it into my *.qml files.
The result is, when I execute it, the video is played on a new window and not on my QML window.
Here is the code :
/* videodisplayitem.h */
#include <QDeclarativeItem>
#include <QX11EmbedContainer>
#include <QtDeclarative>
#include <QProcess>
#include <QtGui>
class VideoDisplayItem : public QDeclarativeItem
{
Q_OBJECT
public:
VideoDisplayItem(QDeclarativeItem *parent =0) : QDeclarativeItem(parent) {
// if I execute container->show(); here, I get the video on a new window
container->show();
QString executable
("/usr/bin/mplayer");
arguments << "-wid";
arguments <<
QString::number(container
->winId
());
arguments << "/myvideo.mp4";
process->start(executable, arguments);
proxy = new QGraphicsProxyWidget(this);
proxy->setWidget(container);
proxy->setPos(-container->sizeHint().width()/2, -container->sizeHint().height()/2);
// if I execute container->show(); here, I get nothing visible
// container->show();
}
private:
QGraphicsProxyWidget *proxy;
};
/* videodisplayitem.h */
#include <QDeclarativeItem>
#include <QX11EmbedContainer>
#include <QtDeclarative>
#include <QProcess>
#include <QtGui>
class VideoDisplayItem : public QDeclarativeItem
{
Q_OBJECT
public:
VideoDisplayItem(QDeclarativeItem *parent =0) : QDeclarativeItem(parent) {
container = new QX11EmbedContainer(NULL);
// if I execute container->show(); here, I get the video on a new window
container->show();
QProcess * process = new QProcess(container);
QString executable("/usr/bin/mplayer");
QStringList arguments;
arguments << "-wid";
arguments << QString::number(container->winId());
arguments << "/myvideo.mp4";
process->start(executable, arguments);
proxy = new QGraphicsProxyWidget(this);
proxy->setWidget(container);
proxy->setPos(-container->sizeHint().width()/2, -container->sizeHint().height()/2);
// if I execute container->show(); here, I get nothing visible
// container->show();
}
private:
QX11EmbedContainer *container;
QGraphicsProxyWidget *proxy;
};
To copy to clipboard, switch view to plain text mode
/* main.cpp */
#include <QtGui/QApplication>
#include "videodisplayitem.h"
int main(int argc, char *argv[])
{
QDeclarativeView view;
qmlRegisterType<VideoDisplayItem>("VideoDisplay", 1, 0, "VideoDisplayItem");
view.
setSource(QUrl::fromLocalFile("file.qml"));
view.show();
return app.exec();
}
/* main.cpp */
#include <QtGui/QApplication>
#include "videodisplayitem.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDeclarativeView view;
qmlRegisterType<VideoDisplayItem>("VideoDisplay", 1, 0, "VideoDisplayItem");
view.setSource(QUrl::fromLocalFile("file.qml"));
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
/* file.qml */
import Qt 4.7
import VideoDisplay 1.0
Rectangle {
width: 300
height: 300
VideoDisplayItem {
anchors.centerIn: parent
}
}
/* file.qml */
import Qt 4.7
import VideoDisplay 1.0
Rectangle {
width: 300
height: 300
VideoDisplayItem {
anchors.centerIn: parent
}
}
To copy to clipboard, switch view to plain text mode
If you get any idea or advise, thanks for all.
My way to proceed might be totally wrong but I dont have any other ideas how to do.
Thanks for all.
Bookmarks