简体   繁体   English

QGraphicView 不显示任何内容

[英]QGraphicView doesn't show anything

I tried to show video using QGraphicView but my code doesn't show anything.我尝试使用 QGraphicView 显示视频,但我的代码没有显示任何内容。 What is the problem问题是什么

QGraphicsScene scene;
QGraphicsVideoItem *item1 = new QGraphicsVideoItem;
item1->setPos(0,100);

QMediaPlayer * player1 = new QMediaPlayer;
player1->setVideoOutput(item1);
player1->setMedia(QUrl("/home/1.wmv"));
QGraphicsView view;
view.scale(0.3,0.3);
view.setScene(&scene);
view.show();
player1->play();

You are creating a QGraphicsVideoItem which you are using as output for a QMediaPlayer and are creating a QGraphicsView on which you assign a QGraphicsScene .您正在创建一个QGraphicsVideoItem ,您将其用作QMediaPlayer输出,并正在创建一个QGraphicsView ,您可以在其上分配QGraphicsScene But you are not connecting the QGraphicsVideoItem (or the QMediaPlayer ) to the QGraphicsView (or the QGraphicsScene ), so obviously nothing gets shown in the QGraphicsView .但你是不是连接QGraphicsVideoItem (或QMediaPlayer )到QGraphicsView (或QGraphicsScene ),所以很明显没有得到中所示QGraphicsView

Note this is only a guesswork answer based on the incomplete code you provided.请注意,这只是基于您提供的不完整代码的猜测答案。 In the future, please be sure to include all relevant code/create a Minimal, Reproducible Example将来,请确保包含所有相关代码/创建一个最小的、可重现的示例

You forgott:你忘了:

scene->addItem(item1);
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QGraphicsScene * scene = new QGraphicsScene();
    QGraphicsView * view = new QGraphicsView(scene);

    QGraphicsVideoItem *item1 = new QGraphicsVideoItem;
    QMediaPlayer * player1 = new QMediaPlayer;

    scene->addItem(item1);
    item1->setPos(0,100);

    view->scale(0.3,0.3);
    view->show();

    player1->setVideoOutput(item1);
    player1->setMedia(QUrl::fromLocalFile("/home/user/Musik/musik.mp4"));

    player1->play();

    return a.exec();
}


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM