1

example image

everyone! I try to set a click property to a QMediaPlayer Element, but I can not find the mode to make it, and if I try to put a button in front to Video, the button puts behind to video, even with

button->raise();
videoWidget->lower();

And If I put a Button to fullscreen the screen turns in black and don't shows the video

this id the code of the video player

QMediaPlayer *player = new QMediaPlayer(this);
QVideoWidget *vw = new QVideoWidget(this);

QMediaPlaylist *PlayList = new QMediaPlaylist(this);
PlayList->addMedia(QUrl::fromLocalFile("/home/user/Videos/video.mp4"));
PlayList->setPlaybackMode(QMediaPlaylist::Loop);

QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(vw);

player->setVideoOutput(vw);
player->setPlaylist(PlayList);

vw->setGeometry(0,0,800,480);
vw->show();
player->play();
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Do you want to capture the click event of the QMediaPlayer or do you want to place a QPushButton in front of the QMediaPlayer? – eyllanesc Jan 03 '18 at 16:57
  • @eyllanesc any way is great for me , but I prefered the button in front of the video, but if you have the solution to capture the click event of the QMediaPlayer is great! – Aarón Gutiérrez Jan 03 '18 at 17:11
  • Could you show a picture of how you want to see the button in front of the QMediaPlayer? – eyllanesc Jan 03 '18 at 17:13
  • @eyllanesc Like this, the blackscreen is the video and the micorsoft store logo is the botton tha I want put https://mega.nz/#!mxVXzLaD!PoIZgM4iclzpq7i3MKBGVKhD2dp9iB9mRgM24hRhcLc – Aarón Gutiérrez Jan 03 '18 at 18:19

1 Answers1

0

One possible solution is to create a widget where the QVideoWidget is placed through a layout, the button is also added and we change the position through the resizeEvent() event.

#include <QApplication>
#include <QMediaPlayer>
#include <QMediaPlaylist>
#include <QPushButton>
#include <QUrl>
#include <QVBoxLayout>
#include <QVideoWidget>

#include <QDebug>

class VideoWidgetButton: public QWidget{
    QPushButton *btn;
    QVideoWidget *vw;
    QMediaPlayer *player;
public:
    VideoWidgetButton(QWidget *parent=Q_NULLPTR):QWidget(parent){
        setLayout(new QVBoxLayout);
        layout()->setContentsMargins(0, 0, 0, 0);

        vw = new QVideoWidget(this);
        btn = new QPushButton(this);
        btn->setIcon(QIcon(":/icons/tux.jpeg"));
        btn->resize(QSize(128, 128));
        btn->setIconSize(QSize(128, 128));

        connect(btn, &QPushButton::clicked, [](){
            qDebug()<<"clicked";
        });

        layout()->addWidget(vw);

        player = new QMediaPlayer(this);
        player->setVideoOutput(vw);

        QMediaPlaylist *playList = new QMediaPlaylist(this);
        playList->addMedia(QUrl("qrc:/video/SampleVideo_1280x720_1mb.mp4"));
        playList->setPlaybackMode(QMediaPlaylist::Loop);
        player->setPlaylist(playList);
        player->play();

    }
protected:
    void resizeEvent(QResizeEvent *ev){
        btn->move(rect().bottomRight()-btn->rect().bottomRight());
        return QWidget::resizeEvent(ev);
    }
};

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    VideoWidgetButton w;
    w.resize(640, 480);
    w.show();
    return a.exec();
}

enter image description here

The complete example can be found in the following link.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • `vw = new QVideoWidget(this);` overoptimized. – user3606329 Jan 03 '18 at 23:03
  • Hey! I tried the code that you sended me, and the result is the same :( Do you think that is problem of Qt? when I execute a program I get this errors `QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root' libGL error: pci id for fd 9: 8086:591b, driver (null) i965_dri.so does not support the 0x591b PCI ID. libGL error: failed to create dri screen libGL error: failed to load driver: i965 ` Also I downloaded the code from git, but is the same result – Aarón Gutiérrez Jan 04 '18 at 22:25
  • That's a problem with your video driver, I do not have that problem. – eyllanesc Jan 04 '18 at 22:27
  • Thanks for your help! I will fix this problem! – Aarón Gutiérrez Jan 04 '18 at 22:43