not renewing (trying to set QWebEngineView on UI)
-
<- this is my working directory
Hello, i'm new at QT programming
i'm going to set webviewer on ui...(framelesswindow.ui/windowContent QWidget)
(At here..)
but when i run this project, my webengineview on that UI do not show my webpage, instead of that, show just white page.
so i clicked anywhere on my application but it didn't workthe weird thing was......
when i click on other program or widows background, the webpage shows seems to be working correctly only at that time, and stop again.
For times i click outside the app, the webpage is working only that time.how can i fix that?
plz help...
main.cpp
#include <QApplication> #include <QWebEngineView> #include "DarkStyle.h" #include "framelesswindow.h" #include <QUrl> #include <QIcon> #include <QDesktopWidget> #include <QDockWidget> #include <QWidget> //#include "mainwindow.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); // style our application with custom dark style a.setStyle(new DarkStyle); // create frameless window (and set windowState or title) FramelessWindow framelessWindow; //framelessWindow.setWindowState(Qt::WindowFullScreen); framelessWindow.setWindowTitle("\354\213\234\353\224\224\354\246\210 \352\262\214\354\236\204\354\235\230\354\236\220"); framelessWindow.setWindowIcon(QIcon("C:/Users/ect/Desktop/wind/icon.ico")); framelessWindow.setFixedSize(1440,1080); QRect screenGeometry = QApplication::desktop()->screenGeometry(); int x = ( (screenGeometry.width() ) - ( framelessWindow.width() ) ) / 2; int y = ( (screenGeometry.height() ) - ( framelessWindow.height() ) ) / 2; QWebEngineView *view = new QWebEngineView(); view->load(QUrl("http://localhost:8898/index.html")); framelessWindow.setContent(view); framelessWindow.move(x,y); framelessWindow.show(); return a.exec(); }
framelesswindow.cpp
#include "framelesswindow.h" #include <QApplication> #include <QDesktopWidget> #include <QGraphicsDropShadowEffect> #include "ui_framelesswindow.h" FramelessWindow::FramelessWindow(QWidget *parent) : QWidget(parent), ui(new Ui::FramelessWindow){ setWindowFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint); #if defined(Q_OS_WIN) setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint); #endif setAttribute(Qt::WA_NoSystemBackground, true); setAttribute(Qt::WA_TranslucentBackground); ui->setupUi(this); // shadow under window title text QGraphicsDropShadowEffect *textShadow = new QGraphicsDropShadowEffect; textShadow->setBlurRadius(4.0); textShadow->setColor(QColor(0, 0, 0)); textShadow->setOffset(0.0); ui->titleText->setGraphicsEffect(textShadow); // window shadow QGraphicsDropShadowEffect *windowShadow = new QGraphicsDropShadowEffect; windowShadow->setBlurRadius(9.0); windowShadow->setColor(palette().color(QPalette::Highlight)); windowShadow->setOffset(0.0); ui->windowFrame->setGraphicsEffect(windowShadow); QObject::connect(qApp, &QGuiApplication::applicationStateChanged, this, &FramelessWindow::on_applicationStateChanged); setMouseTracking(true); // important to watch mouse move from all child widgets QApplication::instance()->installEventFilter(this); } FramelessWindow::~FramelessWindow() { delete ui; } void FramelessWindow::setContent(QWidget *w) { ui->windowContent->layout()->addWidget(w); } void FramelessWindow::setWindowTitle(const QString &text) { ui->titleText->setText(text); } void FramelessWindow::setWindowIcon(const QIcon &ico) { ui->icon->setPixmap(ico.pixmap(16, 16)); } void FramelessWindow::styleWindow(bool bActive, bool bNoState) { if (bActive) { if (bNoState) { layout()->setMargin(15); ui->windowTitlebar->setStyleSheet(QStringLiteral( "#windowTitlebar{border: 0px none palette(shadow); " "border-top-left-radius:5px; border-top-right-radius:5px; " "background-color:palette(shadow); height:20px;}")); ui->windowFrame->setStyleSheet(QStringLiteral( "#windowFrame{border:1px solid palette(highlight); border-radius:5px " "5px 5px 5px; background-color:palette(Window);}")); QGraphicsEffect *oldShadow = ui->windowFrame->graphicsEffect(); if (oldShadow) delete oldShadow; QGraphicsDropShadowEffect *windowShadow = new QGraphicsDropShadowEffect; windowShadow->setBlurRadius(9.0); windowShadow->setColor(palette().color(QPalette::Highlight)); windowShadow->setOffset(0.0); ui->windowFrame->setGraphicsEffect(windowShadow); } else { layout()->setMargin(0); ui->windowTitlebar->setStyleSheet(QStringLiteral( "#windowTitlebar{border: 0px none palette(shadow); " "border-top-left-radius:0px; border-top-right-radius:0px; " "background-color:palette(shadow); height:20px;}")); ui->windowFrame->setStyleSheet(QStringLiteral( "#windowFrame{border:1px solid palette(dark); border-radius:0px 0px " "0px 0px; background-color:palette(Window);}")); QGraphicsEffect *oldShadow = ui->windowFrame->graphicsEffect(); if (oldShadow) delete oldShadow; ui->windowFrame->setGraphicsEffect(nullptr); } // if (bNoState) else maximize } else { if (bNoState) { layout()->setMargin(15); ui->windowTitlebar->setStyleSheet(QStringLiteral( "#windowTitlebar{border: 0px none palette(shadow); " "border-top-left-radius:5px; border-top-right-radius:5px; " "background-color:palette(dark); height:20px;}")); ui->windowFrame->setStyleSheet(QStringLiteral( "#windowFrame{border:1px solid #000000; border-radius:5px 5px 5px " "5px; background-color:palette(Window);}")); QGraphicsEffect *oldShadow = ui->windowFrame->graphicsEffect(); if (oldShadow) delete oldShadow; QGraphicsDropShadowEffect *windowShadow = new QGraphicsDropShadowEffect; windowShadow->setBlurRadius(9.0); windowShadow->setColor(palette().color(QPalette::Shadow)); windowShadow->setOffset(0.0); ui->windowFrame->setGraphicsEffect(windowShadow); } else { layout()->setMargin(0); ui->windowTitlebar->setStyleSheet(QStringLiteral( "#titlebarWidget{border: 0px none palette(shadow); " "border-top-left-radius:0px; border-top-right-radius:0px; " "background-color:palette(dark); height:20px;}")); ui->windowFrame->setStyleSheet(QStringLiteral( "#windowFrame{border:1px solid palette(shadow); border-radius:0px " "0px 0px 0px; background-color:palette(Window);}")); QGraphicsEffect *oldShadow = ui->windowFrame->graphicsEffect(); if (oldShadow) delete oldShadow; ui->windowFrame->setGraphicsEffect(nullptr); } // if (bNoState) { else maximize } // if (bActive) { else no focus } void FramelessWindow::on_applicationStateChanged(Qt::ApplicationState state) { if (windowState().testFlag(Qt::WindowNoState)) { if (state == Qt::ApplicationActive) { styleWindow(true, true); } else { styleWindow(false, true); } } else if (windowState().testFlag(Qt::WindowFullScreen)) { if (state == Qt::ApplicationActive) { styleWindow(true, false); } else { styleWindow(false, false); } } } void FramelessWindow::on_closeButton_clicked() { close(); }
-
Hi and welcome to devnet,
Before doing any kind of styling modification, I would first go with just FramelessWindow and the addition of your web view to it. Comment out all the rest of the code and check whether you can see the page properly. Once that this is cleared, re-add gradually the commented code to see when it breaks.
-
hello, I kept googling and found this thread. and my problem is same.
in my test, the reason maybe 'textShadow->setBlurRadius(4.0)' .
I don't know the exact reason either, but i think if set blur radius by QGraphicsDropShadowEffect, then redering process ofweb view engine is conflicted with QDialog.So in my case, change frameless dialog and delete setBlurRadius.
sorry to nothing help, but i wanted to write you to the reason.
-