I have the following code and I want to make my QWebEngineView
(Qt 5.8) to go full screen. My WebView
class is under a QTabWidget
so it's just fill 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));
}
}
If your widget is inside a tab, then it can't be full screen directly. You have two options:
QTabWidget
when quitting the fullscreen mode. QTabWidget
to fulfill the screen. 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...
I have found a way to do this ,so I am answering my own question : I can change the acceptFullScreen
function as :
void acceptFullScreen(QWebEngineFullScreenRequest request){
if(request.toggleOn()){
request.accept();
QWidget* w=(QWidget*)this->view->parent();
this->layout=w->layout();
this->layout->removeWidget(this->view);
this->view->setParent(0);
this->view->showFullScreen();
}
else{
request.accept();
this->layout->addWidget(this->view);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.