简体   繁体   中英

Dynamically add QWebEngineView to layout

I'm trying to dynamically QWebEngineView to already existing layout.

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QWebEngineView view;
    view.setUrl(QUrl(QStringLiteral("http://www.qt.io")));
    view.resize(1024, 750);
    view.show();
    ui->splitter->addWidget(view);  
}

When running this i'm getting error: C2664: 'void QSplitter::addWidget(QWidget *)': cannot convert argument 1 from 'QWebEngineView' to 'QWidget *'

I'm trying to create program for previewing and editing html/text/image files in local file system. This means that i need to switch widget in main window for different tasks. In my designer form I have splitter layout in which I'm trying to add QWebEngineView.

I tried default examples from Qt Designer for WebEngine and WebKit. They work just as planned but instead of using UI layout they are using only code for adding and managing widgets. I want to use form layouts, which means that this option is not suited for me.

How i can fix this issue ? Is this viable solution for what i'm trying to achieve or there is a better one ?

Try this way:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QWebEngineView *view;
    view = new QWebEngineView(this);
    view->setUrl(QUrl(QStringLiteral("http://www.qt.io")));
    view->resize(1024, 750);
    view->show();
    ui->splitter->addWidget(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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM