c++qtfullscreenqtwebengineqt5.8

How to make QWebEngineView go fullscreen?


I have the following code, and I want to make my QWebEngineView (Qt 5.8) to go full screen.

My WebView class is contained in a QTabWidget, so it just fills up the tab, not entire screen.

How can I make it go fullscreen?

class WebView:public QObject{
    void acceptFullScreen(QWebEngineFullScreenRequest request){
        request.accept();
    }

public:
    char* home_page;
    QWebEngineView* view=new QWebEngineView();
    WebView(char* page=(char*)"file:///home/tarptaeya/Desktop/Crusta_Prototype_python/about.html"){
        this->home_page=page;
        createWebView();
        this->view->settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled,true);
        this->view->settings()->setAttribute(QWebEngineSettings::PluginsEnabled,true);
        this->view->settings()->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows,true);
        connect(this->view->page(),&QWebEnginePage::fullScreenRequested,this,&WebView::acceptFullScreen);
    }
    void createWebView(){
        this->view->load(QUrl(this->home_page));
    }
}

Solution

  • If your widget is inside a tab, then it can't be full screen directly. You have two options:

    In both cases you can use something like this to make it occupy the whole screen:

    // Replace the 0 with the screen index
    const auto windowGeometry = qApp->desktop()->availableGeometry(0);
    widget.move(windowGeometry.topLeft());
    widget.resize(windowGeometry.size());
    

    It will fulfill the screen but will keep the taskbar visible (in my experience this is highly recommended, so the user can easily switch to other tasks). If you want to cover it, just use geometry() instead of the availableGeometry() method.

    EDIT in both cases the widget will have the windows manager frame. If you want to remove it you may try setting the Qt::FramelessWindowHint flag. Take into consideration that removing frame may also make some actions unavailable (at least on Windows) such as moving, resizing, snapping...