spring
spring

Reputation: 18497

using QWebEngine without margins

I am trying to get QWebEngine to fill the entire window. Per this answer I am trying to use setContentsMargins(0,0,0,0); with the result below: the QWebEngine loads the page at full window size but then immediately scales down to this:

enter image description here

When I use setContentsMargins(1,1,1,1); with the QWebEngine in the layout, it loads correctly, with a 1 px margin. I did a test of just loading the image directly, with no margin and it loaded fine and filled the screen.

Is this my bug/issue or QWebEngine's?


#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtWebEngineWidgets>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->setContentsMargins(0,0,0,0);
    ui->centralWidget->setLayout(mainLayout);

//    // load and show image
//    inputImg = new QImage(":/images/testScreen.jpg");
//    imgDisplayLabel = new QLabel("");
//    imgDisplayLabel->setPixmap(QPixmap::fromImage(*inputImg));
//    imgDisplayLabel->adjustSize();
//     mainLayout->addWidget(imgDisplayLabel);

    view = new QWebEngineView(this);
     mainLayout->addWidget(view);

    QUrl url;
    url = QUrl("qrc:/testScreen.html");
    view->load(url);
}

Upvotes: 2

Views: 1018

Answers (1)

R.J
R.J

Reputation: 424

This is working for me but I'm testing on windows platform. I inlined the constructor definition here for brevity.

class MainWindow : public QWidget
{
    Q_OBJECT

public:
    MainWindow() {
        auto webView = new QWebEngineView(this);
        auto main_layout = new QVBoxLayout(this);
        main_layout->setMargin(0);
        main_layout->addWidget(webView);
    }
};

And the html is like this:

<!DOCTYPE html>
<html style="width: 100%; height: 100%; margin: 0; padding: 0">
  <body style="overflow: hidden; width: 100%; height: 100%; margin: 0; padding: 0">
  </body>
</html>

Upvotes: 2

Related Questions