QQuickWidget in Widgets Application
-
Hi,
i'm developing qt widgets application and I want to add QML object into UI. I'm using QuickWidget like this:
@QuickWidget::QuickWidget(QWidget *parent)
: QQuickWidget(parent)
{
setSource(QUrl(QStringLiteral("qrc:/test1.qml")));
}@Then I promoted QWidget to QuickWidget. As I run the app, the widget is filled with "UI copy" (have no idea why..) and the QML area is filled with black color like this:
!http://www.stud.fit.vutbr.cz/~xzakma01/qt/ui1.png(UI1)!
If I resize the application window, the UI changes and insted of black area the QML file is displayed, but also inside whole UI copy like this:
!http://www.stud.fit.vutbr.cz/~xzakma01/qt/ui2.png(UI2)!
Could anyone help me solve this? I tested my code on simple app (only 1 QTabWidget with 2 tabs) an it works great. So the problem is not in non-working QML.
Thanks for any advice.
-
Ok,
I did some more investigation and find out the problem is caused with this line:
@player->setVideoOutput(videoWidget);@
In the previous tab "Camera" is only one QWidget named videoContainer.
Here is code I'm using to add video into this QWidget:@ // init player
player = new QMediaPlayer;// init playlist playlist = new QMediaPlaylist(player); // add video files from local disk playlist->addMedia(QUrl::fromLocalFile("....")); playlist->addMedia(QUrl::fromLocalFile("...")); // playlist index playlist->setCurrentIndex(1); // play in loop playlist->setPlaybackMode(QMediaPlaylist::Loop); player->setPlaylist(playlist); // ui video frame QWidget *qw = ui->videoContainer; // init video widget videoWidget = new QVideoWidget(qw); videoWidget->setMinimumSize(400,300); // THIS CAUSES THE ERROR - assign output widget player->setVideoOutput(videoWidget);@
Could this be a bug or am I using it wrong way?
Thanks for any help.