Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to toggle a window from fullscreen to normal mode programmatically?

I am using this code to toggle a window from normal mode to fullscreen:

void MainWindow::on_action_Fullscreen_triggered()
{
    showFullScreen();
}

How to return back to normal mode when I trigger this action again?

like image 636
GeoMint Avatar asked Oct 30 '25 12:10

GeoMint


1 Answers

The answer of LogicStuff is almost perfect but it does not account for whether the window was maximized or not. Personally I always use this little snippet:

void main_window::toggle_fullscreen()
{
    isFullScreen() ?
        ((was_maximized_) ? showMaximized() : showNormal()), ui_->menu_view_toggle_fullscreen->setIcon(QIcon(":/fullscreen_enter")) :
        ((was_maximized_ = isMaximized()), showFullScreen(), ui_->menu_view_toggle_fullscreen->setIcon(QIcon(":/fullscreen_exit")));
}

Since showFullScreen() also affects the isMaximized() return value, we have to save it somewhere (was_maximized_) before going full screen.

like image 166
S. Broekman Avatar answered Nov 01 '25 13:11

S. Broekman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!