Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. How to add widgets to QWebEngineView?
Forum Updated to NodeBB v4.3 + New Features

How to add widgets to QWebEngineView?

Scheduled Pinned Locked Moved Unsolved QtWebEngine
3 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MozzieM Offline
    MozzieM Offline
    Mozzie
    wrote on last edited by JKSH
    #1

    Hi,
    I am customizing a web browser,
    but when I want to add some widgets to my QWebENgineVIew,
    I have to resize the widget every time before it shows.

    
    MyWebEngineView::MyWebEngineView(*parent) : QWebEngineView(parent)
    {
    	QVBoxLayout* layout = qobject_cast<QVBoxLayout*>(this->layout());
    	qDebug() << layout;
    	if (nullptr == layout) {
    		layout = new QVBoxLayout(this);
    	}
    	layout->setSpacing(0);
    	QToolBar* toolBar = createToolBar();
    	layout->addWidget(toolBar);
    	progressBar = new QProgressBar(this);
    	progressBar->setMaximumHeight(1);
    	progressBar->setTextVisible(false);
    	progressBar->setStyleSheet(QStringLiteral("QProgressBar {border: 0px} QProgressBar::chunk {background-color: #da4453}"));
    	layout->addWidget(progressBar);
    
    	this->extendToolWidget = new QWidget(this);
    	this->extendToolWidget->hide();
    	layout->addWidget(this->extendToolWidget);
    }
    
        MyWebView *webView = new MyWebView;
        MyWebPage *webPage = new MyWebPage(QWebEngineProfile::defaultProfile(), webView);
        webView->setPage(webPage);
    
        setupView(webView);
        webView->resize(currentWidget()->size());
        webView->show();
    

    and when I show this widget , I can see my tool bar move from center to top, rather than always on the top.

    so what can i do to make my tool ba stay on the top, Thank you.

    JonBJ 1 Reply Last reply
    0
    • MozzieM Mozzie

      Hi,
      I am customizing a web browser,
      but when I want to add some widgets to my QWebENgineVIew,
      I have to resize the widget every time before it shows.

      
      MyWebEngineView::MyWebEngineView(*parent) : QWebEngineView(parent)
      {
      	QVBoxLayout* layout = qobject_cast<QVBoxLayout*>(this->layout());
      	qDebug() << layout;
      	if (nullptr == layout) {
      		layout = new QVBoxLayout(this);
      	}
      	layout->setSpacing(0);
      	QToolBar* toolBar = createToolBar();
      	layout->addWidget(toolBar);
      	progressBar = new QProgressBar(this);
      	progressBar->setMaximumHeight(1);
      	progressBar->setTextVisible(false);
      	progressBar->setStyleSheet(QStringLiteral("QProgressBar {border: 0px} QProgressBar::chunk {background-color: #da4453}"));
      	layout->addWidget(progressBar);
      
      	this->extendToolWidget = new QWidget(this);
      	this->extendToolWidget->hide();
      	layout->addWidget(this->extendToolWidget);
      }
      
          MyWebView *webView = new MyWebView;
          MyWebPage *webPage = new MyWebPage(QWebEngineProfile::defaultProfile(), webView);
          webView->setPage(webPage);
      
          setupView(webView);
          webView->resize(currentWidget()->size());
          webView->show();
      

      and when I show this widget , I can see my tool bar move from center to top, rather than always on the top.

      so what can i do to make my tool ba stay on the top, Thank you.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Mozzie
      I could be quite mistaken here, but

          webView->resize(currentWidget()->size());
          webView->show();
      

      You are calling size()/resize() before the widget/webview has been shown. Sometimes (always?) sizing info is not ready before show. You should at least debug out what size that is doing? Do you need to do it later, after showing has happened (e.g. https://doc.qt.io/qt-5/qwebenginepage.html#loadFinished)??

      MozzieM 1 Reply Last reply
      1
      • JonBJ JonB

        @Mozzie
        I could be quite mistaken here, but

            webView->resize(currentWidget()->size());
            webView->show();
        

        You are calling size()/resize() before the widget/webview has been shown. Sometimes (always?) sizing info is not ready before show. You should at least debug out what size that is doing? Do you need to do it later, after showing has happened (e.g. https://doc.qt.io/qt-5/qwebenginepage.html#loadFinished)??

        MozzieM Offline
        MozzieM Offline
        Mozzie
        wrote on last edited by
        #3

        @JonB
        hi,
        I have debuged this code

            webView->resize(currentWidget()->size());
            webView->show();
        

        and the currentWidget is already shown before I create a new webView, so the size is correct.
        and actually my situation is before I load a url, everytime when I create a blank webview with my toolbar and show it, I have to call this code up there, but I can see my tool bar move from center to top, if not, my toolbar just stay on the center,

        It is not like other widget if you create a new widget when you show it, you don't need to resize and the widgets in it's layout is right on their position.

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved