How to Fullscreen the child widget
How to Fullscreen the child widget
Un-subscribe from this thread
How to Fullscreen the child widget
The UI is as following
http://img.my.csdn.net/uploads/201212/06/1354779576_2592.jpg
What I want to do is that
When doubleclick the black widget ,it should become in full screen mode ,then if I doubleclick again ,it should return back .
So how to ?
showFullScreen()only affects windows
but when I setWindowFlags(Qt.Window) of that black widget ,the UI becomes like this
http://img.my.csdn.net/uploads/201212/06/1354779928_2090.jpg
so how can I implement this functionality ?
BTW ,Phonon.VideoWidget Inherits QWidget and it has setFullScreen() method ,who know how it is implemented ?
it would be better to give me some code example !
9 replies
The black widget lies inside the MainWindow of your application , so as per my understanding when you doubleClick on the black widget you want to maximize the application and if maximized then on double click you want to resize it back.
One option is to subclass QWidget( for your black Widget) and reimplement mouseDoubleClick() function.
Here is a test code :-
MyWidget.h
- {
- Q_OBJECT
- public:
- protected:
- signals:
- void doubleClicked();
- public slots:
- void onDoubleClicked();
- };
MyWidget.cpp
- {
- connect(this,SIGNAL(doubleClicked()),SLOT(onDoubleClicked()));
- }
- {
- emit doubleClicked();
- }
- void MyWidget::onDoubleClicked()
- {
- if (parentWidget()->isMaximized())
- {
- // you can implement to move the mainwindow to the center of screen.
- qDebug() << parentWidget(); //to see if parentWidget is mainwindow
- this->parentWidget()->resize(300,300);
- } else
- {
- this->parentWidget()->showMaximized();
- }
- }
Other option is that in your mainwindow you can override eventFilter() function and use installEventFilter() for your widget.
code:-
MainWindow.h
- {
- Q_OBJECT
- public:
- ~MainWindow();
- public slots:
- void onDoubleClicked();
- signals:
- void doubleClicked();
- protected:
- private:
- Ui::MainWindow *ui;
- };
MainWindow.cpp
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- widget->installEventFilter(this);
- widget->setAutoFillBackground(true);
- setCentralWidget(widget);
- connect(this,SIGNAL(doubleClicked()),SLOT(onDoubleClicked()));
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::onDoubleClicked()
- {
- if (isMaximized())
- {
- resize(300,300);
- } else
- {
- showMaximized();
- }
- }
- {
- if (target == widget)
- {
- {
- {
- emit doubleClicked();
- }
- }
- }
- }
The black widget lies inside the MainWindow of your application , so as per my understanding when you doubleClick on the black widget you want to maximize the application and if maximized then on double click you want to resize it back.One option is to subclass QWidget( for your black Widget) and reimplement mouseDoubleClick() function.
Here is a test code :-
MyWidget.h
{ Q_OBJECT public: protected: signals: void doubleClicked(); public slots: void onDoubleClicked(); };MyWidget.cpp
{ connect(this,SIGNAL(doubleClicked()),SLOT(onDoubleClicked())); } { emit doubleClicked(); } void MyWidget::onDoubleClicked() { if (parentWidget()->isMaximized()) { // you can implement to move the mainwindow to the center of screen. qDebug() << parentWidget(); //to see if parentWidget is mainwindow this->parentWidget()->resize(300,300); } else { this->parentWidget()->showMaximized(); } }Other option is that in your mainwindow you can override eventFilter() function and use installEventFilter() for your widget.
code:-
MainWindow.h
{ Q_OBJECT public: ~MainWindow(); public slots: void onDoubleClicked(); signals: void doubleClicked(); protected: private: Ui::MainWindow *ui; };MainWindow.cpp
@MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
widget = new QWidget(this); widget->installEventFilter(this); widget->setAutoFillBackground(true); widget->setPalette(QPalette(Qt::red)); setCentralWidget(widget); connect(this,SIGNAL),SLOT));
{ ui->setupUi(this);}
MainWindow::~MainWindow()
{ delete ui;
}void MainWindow::onDoubleClicked()
} else { showMaximized(); } }
{ if (isMaximized()) { resize(300,300);bool MainWindow::eventFilter(QObject *target, QEvent *event)
{ if (target widget) { if (event->type() QEvent::MouseButtonDblClick) { QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); if (mouseEvent->button() == Qt::LeftButton ) { emit doubleClicked(); return QMainWindow::eventFilter(target,event); } } } return QMainWindow::eventFilter(target,event);
}@
NOTE : When doubleclick the black widget ,it should become in full screen mode ,i.e. the full screen of my computer should become black (that is just like a player play video in full screen mode )then if I doubleclick again ,it should return back .
NOTE : When doubleclick the black widget ,it should become in full screen mode ,i.e. the full screen of my computer should become black (that is just like a player play video in full screen mode )then if I doubleclick again ,it should return back .
Thats more easy just set the following for your widget
bq. NOTE : When doubleclick the black widget ,it should become in full screen mode ,i.e. the full screen of my computer should become black (that is just like a player play video in full screen mode )then if I doubleclick again ,it should return back .Qt::WindowFullScreen only affects windows,but here the black widget is not window .Thats more easy just set the following for your widget
@setWindowFlags(this->windowFlags() | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint);
setWindowState(this->windowState() | Qt::WindowFullScreen);@
Okay here is the complete implementation
MainWindow.h
- {
- Q_OBJECT
- public:
- ~MainWindow();
- public slots:
- void onDoubleClicked();
- signals:
- void doubleClicked();
- protected:
- private:
- Ui::MainWindow *ui;
- bool isMaximized;
- };
MainWindow.cpp
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- isMaximized = false;
- widget->installEventFilter(this);
- widget->setAutoFillBackground(true);
- setCentralWidget(widget);
- connect(this,SIGNAL(doubleClicked()),SLOT(onDoubleClicked()));
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::onDoubleClicked()
- {
- {
- qDebug("Parent");
- widget->setParent(this);
- setCentralWidget(widget);
- isMaximized = false;
- } else
- {
- qDebug("Maximize");
- isMaximized = true;
- widget->setParent(NULL);
- widget->show();
- }
- }
- {
- if (target == widget)
- {
- {
- {
- emit doubleClicked();
- }
- }
- }
- }
This works as required.
… http://img.my.csdn.net/uploads/201212/06/1354779576_2592.jpg … http://img.my.csdn.net/uploads/201212/06/1354779928_2090.jpg …
Hi I’m new but interested in this thread. The access to the jpgs is “403 Forbidden” ??!!
bernd
You must log in to post a reply. Not a member yet? Register here!



