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 !



  • the black widget is QWidget



  • 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

    @class MyWidget : public QWidget
    {
    Q_OBJECT
    public:
    explicit MyWidget(QWidget *parent = 0);

    protected:
    void mouseDoubleClickEvent(QMouseEvent *event);

    signals:
    void doubleClicked();
    public slots:
    void onDoubleClicked();

    };@

    MyWidget.cpp

    @MyWidget::MyWidget(QWidget *parent) :
    QWidget(parent)
    {
    connect(this,SIGNAL(doubleClicked()),SLOT(onDoubleClicked()));
    }

    void MyWidget::mouseDoubleClickEvent(QMouseEvent *event)
    {
    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

    @
    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    public slots:
    void onDoubleClicked();

    signals:
    void doubleClicked();

    protected:
    void mousePressEvent(QMouseEvent *event);
    bool eventFilter(QObject *target, QEvent *event);

    private:
    Ui::MainWindow *ui;
    QWidget *widget;

    };@

    MainWindow.cpp

    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    widget = new QWidget(this);
    widget->installEventFilter(this);
    widget->setAutoFillBackground(true);
    widget->setPalette(QPalette(Qt::red));
    
    setCentralWidget(widget);
    
    connect(this,SIGNAL(doubleClicked()),SLOT(onDoubleClicked()));
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::onDoubleClicked()
    {
    if (isMaximized())
    {
    resize(300,300);

    } else
    {
        showMaximized();
    }
    

    }

    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);
    }@



  • [quote author="Sam" date="1358402050"]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

    @class MyWidget : public QWidget
    {
    Q_OBJECT
    public:
    explicit MyWidget(QWidget *parent = 0);

    protected:
    void mouseDoubleClickEvent(QMouseEvent *event);

    signals:
    void doubleClicked();
    public slots:
    void onDoubleClicked();

    };@

    MyWidget.cpp

    @MyWidget::MyWidget(QWidget *parent) :
    QWidget(parent)
    {
    connect(this,SIGNAL(doubleClicked()),SLOT(onDoubleClicked()));
    }

    void MyWidget::mouseDoubleClickEvent(QMouseEvent *event)
    {
    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

    @
    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    public slots:
    void onDoubleClicked();

    signals:
    void doubleClicked();

    protected:
    void mousePressEvent(QMouseEvent *event);
    bool eventFilter(QObject *target, QEvent *event);

    private:
    Ui::MainWindow *ui;
    QWidget *widget;

    };@

    MainWindow.cpp

    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    widget = new QWidget(this);
    widget->installEventFilter(this);
    widget->setAutoFillBackground(true);
    widget->setPalette(QPalette(Qt::red));
    
    setCentralWidget(widget);
    
    connect(this,SIGNAL(doubleClicked()),SLOT(onDoubleClicked()));
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::onDoubleClicked()
    {
    if (isMaximized())
    {
    resize(300,300);

    } else
    {
        showMaximized();
    }
    

    }

    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);
    }@[/quote]

    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 .



  • 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 .

    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);@



  • [quote author="Sam" date="1358407182"]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 .

    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);@[/quote]

    Qt::WindowFullScreen only affects windows,but here the black widget is not window .



  • bq. Qt::WindowFullScreen only affects windows,but here the black widget is not window

    Are you sure ? coz that works for me , test code :-

    @widget = new QWidget();
    widget->setAutoFillBackground(true);
    widget->setPalette(QPalette(Qt::red));

    widget->setWindowFlags(widget->windowFlags() | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint);
    widget->setWindowState(widget->windowState() | Qt::WindowFullScreen);

    widget->show();@



  • Okay here is the complete implementation

    MainWindow.h

    @class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    public slots:
    void onDoubleClicked();

    signals:
    void doubleClicked();

    protected:
    bool eventFilter(QObject *target, QEvent *event);

    private:
    Ui::MainWindow *ui;
    QWidget *widget;
    bool isMaximized;
    };@

    MainWindow.cpp
    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    isMaximized = false;
    widget = new QWidget(this);
    widget->installEventFilter(this);
    widget->setAutoFillBackground(true);
    widget->setPalette(QPalette(Qt::red));
    
    setCentralWidget(widget);
    connect(this,SIGNAL(doubleClicked()),SLOT(onDoubleClicked()));
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::onDoubleClicked()
    {
    if ((widget->windowState() == Qt::WindowFullScreen) && isMaximized)
    {
    qDebug("Parent");
    widget->setParent(this);
    setCentralWidget(widget);
    isMaximized = false;

    } else
    {
        qDebug("Maximize");
        isMaximized = true;
        widget->setParent(NULL);
        widget->setWindowFlags(widget->windowFlags() | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint);
        widget->setWindowState(widget->windowState() | Qt::WindowFullScreen);
        widget->show();
    
    }
    

    }

    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);
    }@

    This works as required.



  • [quote author="redstoneleo" date="1358384982"]...
    http://img.my.csdn.net/uploads/201212/06/1354779576_2592.jpg
    ...
    http://img.my.csdn.net/uploads/201212/06/1354779928_2090.jpg
    ...
    [/quote]

    Hi I'm new but interested in this thread. The access to the jpgs is "403 Forbidden" ??!!

    bernd




Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.