简体   繁体   English

QVideoWidget对齐后不显示任何内容

[英]QVideoWidget doesn't show anything when aligned

I've got a strange problem and need some help. 我遇到了一个奇怪的问题,需要一些帮助。 The situation is quiet easy: I have a QMediaPlayer , QVideoWidget and some layout (ex. QVboxLayout ; well, it doesn't really matter). 情况很简单:我有一个QMediaPlayerQVideoWidget和一些布局(例如QVboxLayout ;实际上,这并不重要)。 The problem is when I add QVideoWidget with alignment specified - video doesn't show up, there's only a place for the widget, a blank area with no video. 问题是当我添加具有指定对齐方式的QVideoWidget时-视频未显示,该窗口小部件只有一个位置,没有视频的空白区域。 And there's no problem if I add it without specifying alignment. 如果我不指定对齐就添加它也没有问题。 Here's the code example: 这是代码示例:

Widget.h: Widget.h:

class Widget : public QWidget
{
  Q_OBJECT

public:
  Widget(QWidget *parent = 0)
    : QWidget(parent)
  {
    QVideoWidget *vw = new QVideoWidget();
    QVBoxLayout *vb = new QVBoxLayout();
    vb->addWidget(vw, 0/*, Qt::AlignCenter*/); /// << here's the problem block
    this->setLayout(vb);

    QMediaPlayer *pl = new QMediaPlayer();
    pl->setMedia(QMediaContent(
                   QUrl::fromLocalFile("D:/1.wmv")));
    pl->setVideoOutput(vw);
    pl->play();
    this->resize(600, 480);
  }
  ~Widget() {}
};

Any suggestions? 有什么建议么? Thanks in advance. 提前致谢。

UPD: UPD:

Found an interesting thing - if "qDebugging" geometry() of video widget with center alignment " off " it looks like this: QRect(11,11 579x459) But if I try to align it to the center it looks like this: QRect(300,240 0x0) 发现了一件有趣的事情-如果视频小部件的“ qDebugging” geometry()中心对齐为“ off ”,它看起来像这样: QRect(11,11 579x459)但是如果我尝试将它对齐到中心,它看起来像这样: QRect( 300,240 0x0)

AlignLeft: QRect(11,11 0x456) AlignLeft: QRect(11,11 0x456)

Don't know why this happening and what is the right way to resolve this issue, but it repeats even if I change QVideoWidget with QGraphicsScene-QGraphicsView-QGraphicsVideoItem chain. 不知道为什么会这样,以及解决此问题的正确方法是什么,但是即使我使用QGraphicsScene-QGraphicsView-QGraphicsVideoItem链更改了QVideoWidget ,它也会重复执行。

Well, here on stackoverflow (sorry, missed the exactly link) I've found the advice not to use alignment on widgets in layout, instead it's better to use alignment inside the widgets that have to be aligned. 好吧,在stackoverflow上(抱歉,错过了确切的链接),我发现建议不要在布局中的小部件上使用对齐方式,而是最好在必须对齐的小部件中使用对齐方式。 That's why I've turned layout's alignment off and centered the content of the widgets, that are inserted into the layout. 这就是为什么我关闭布局的对齐方式并将居中控件的内容居中的原因,这些控件已插入到布局中。 Looks like a hack, but it really works. 看起来像骇客,但确实有效。 Thanks for the help. 谢谢您的帮助。

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

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