PDA

View Full Version : QVideoWidget Fullscreen



antweb
27th May 2015, 06:39
I want to make my QVideoWidget fullscreen on mouse click and back.
I've implemented the mouse click and have tried two methods to go fullscreen but both are not working.

Method 1:

w->setWindowState(w->windowState() ^ Qt::WindowFullScreen);
And to come back

w->setWindowState(w->windowState() & ~Qt::WindowMinimized | Qt::WindowActive);

Nothing happens in this case.

Method 2: (found after some good internet searching)


void mousePressEvent(QMouseEvent*) {
if (maxMode== false)
{
m_enOrigWindowFlags = this->windowFlags();
m_pSize = this->size();
this->setParent(0);
this->setWindowFlags( Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);
this->showFullScreen();
maxMode = true;
}
else
{
this->setParent(m_pParent);
this ->resize(m_pSize);
this->overrideWindowFlags(m_enOrigWindowFlags);
this->show();
maxMode = false;
}
}
};

This method works fine to get to fullscreen. But on the second click the video widget comes in a new window and not on the original position on the Ui.

Please help me. Thanks!

wysota
27th May 2015, 09:52
QWidget::showNormal()


void mousePressEvent(QMouseEvent*) {
maxMode = !maxMode;
if(maxMode) showFullscreen(); else showNormal();
};

antweb
27th May 2015, 11:08
Nothing happens Sir.
No change in the widget!

wysota
27th May 2015, 11:58
What exactly did you change? What does the code currently look like?

antweb
27th May 2015, 13:33
this is my .h file



#ifndef MYTCPSOCKET_H
#define MYTCPSOCKET_H

#include <QMainWindow>
#include <QTcpSocket>
#include <QUdpSocket>
#include <QAbstractSocket>
#include <QProcess>
#include <QDebug>
#include <QMediaPlayer>
#include <QVideoWidget>
#include <QProcess>

namespace Ui {
class MyTcpSocket;
class ClickableVideo;
}

class ClickableVideo : public QVideoWidget
{
Q_OBJECT
public:
ClickableVideo(QWidget *parent = 0) : QVideoWidget(parent) {
m_pParent = parent;
maxMode = false;
maxMode1 = false;
maxMode2 = false;
maxMode3 = false;
connect(this, SIGNAL(clicked()), this, SLOT(slotClicked()));
}
QWidget* m_pParent;
bool maxMode,maxMode1,maxMode2,maxMode3;
Qt::WindowFlags m_enOrigWindowFlags;
QSize m_pSize;

signals:
void clicked(void);
void reconnect(void);

public slots:
void slotClicked();

protected:
void mouseReleaseEvent(QMouseEvent* event) // or double clicked or what you want
{
emit this->clicked();
}

private:
Ui::ClickableVideo *ui;
};

class MyTcpSocket : public QMainWindow
{
Q_OBJECT

public:
explicit MyTcpSocket(QWidget *parent = 0);
~MyTcpSocket();
void doConnect();
void session_splitter(QByteArray &received_data);
void rtp_to_frame_splitter(QByteArray &received_data);

private:
Ui::MyTcpSocket *ui;

signals:
public slots:
void connected();
void disconnected();
void reconnect_widget();
void bytesWritten(qint64 bytes);
void readyRead();
void on_pushButton_clicked();
void on_pushButton_4_clicked();

private:
QProcess *mInputPlayProcess;
QTcpSocket *socket;
QTcpSocket *send_socket;
QMediaPlayer *player1;
QMediaPlayer *player2;
QMediaPlayer *player3;
QMediaPlayer *player4;
ClickableVideo *videoWidget1;
ClickableVideo *videoWidget2;
ClickableVideo *videoWidget3;
ClickableVideo *videoWidget4;
};

#endif // MYTCPSOCKET_H


In my mytcpsocket.cpp file I have implemented the slot like this


void ClickableVideo::slotClicked()
{
//QObject *pobj;
//pobj = this->sender();
//QString str = pobj->objectName();
//if(str == "videoWidget1")
//{
if (maxMode== false)
{
//this->setParent(0);
this->showFullScreen();
maxMode = true;
}
else
{
emit this->reconnect();
this->showNormal();
maxMode = false;
}
//}
}


Two additional things I want to ask:
The objectname doesn't give me a name because videowidget is not part of the Ui file. So how can I seperate out between various widgets.
And if I uncomment setparent(0) it goes to fullscreen but as it was happening earlier comes back to normal size in another window!
Please Help!

Added after 47 minutes:

Also why isn't this connection working?
connect(videowidget1,SIGNAL(reconnect()),this,SLOT (reconnect_widget()));
This has been done in the constructor of mytcpsocket but it isn't going to the slot on emitting the signal? Why?

wysota
27th May 2015, 15:46
And if I uncomment setparent(0) it goes to fullscreen but as it was happening earlier comes back to normal size in another window!

Restore the parent to the original value when returning from full screen.

antweb
27th May 2015, 16:30
I did that as well as you can see in my original post. It still opens in another window!

wysota
27th May 2015, 17:32
I did that as well as you can see in my original post. It still opens in another window!

No, that's not possible. Are you sure m_pParent is initialized properly?

antweb
28th May 2015, 07:15
Yes, I'm getting no value in the parent.
If I'm placing my video widget in a horizontal layout so will that be the parent?

wysota
28th May 2015, 07:25
Yes, I'm getting no value in the parent.
What does that mean?


If I'm placing my video widget in a horizontal layout so will that be the parent?
No, layouts are not parents of a widget. If you really have to do manipulations like that then store a pointer to the parent just before you call setParent(0). However in my opinion it is better to hide all siblings of the player but the player itself and then show its window in full screen. When going back from full screen, show back the widgets you hid earlier.

antweb
28th May 2015, 07:38
Okay, so I set the parent correctly, but in this case when I come back from my full screen my widget is blank although on clicking again it goes to fullscreen but on coming back it goes black.

wysota
28th May 2015, 08:14
So is it blank or black?

What about the approach I suggested?