c++ - Is Qt 5.5's QWebEngineView compatible with FramelessWindowHint? -


i'm writing cross-platform web browser in qt, since has built-in webkit support via qwebview or more up-to-date qwebengineview. compact window chrome, want disable native window title bar , border via qt::framelesswindowhint, still native behavior resizing , windows' aero snap.

first trimmed down pke's borderlesswindow demo. worked fine: on windows 8.1 x64, window resizable, custom title bar can dragged or double-clicked, , aero snap works.

then tried replacing central qlabel qwebengineview. caused gray native-size borders appear around window. when have interactive widgets @ top of window (like menu or toolbar), "ghost" title bar qwebengineview pushes them down accepts cursor clicks in place.

here's screenshot comparing 2 windows. (view on dark background better see light-gray border on right.)

qlabel , qwebengineview windows

is qwebengineview @ compatible frameless window, or should deal wasted space of native window chrome?


edit: replacing qwebengineview qwebview avoids problem:

qwebview window

however, webview deprecated , webengine has more useful features:

  • renders chromium's blink instead of safari's webkit
  • multiprocess, can run javascript without locking ui
  • doesn't leak browser plugin details on panopticlick (try it, qwebview populates navigator.plugins in javascript qwebengineview not)

still, i'd prefer not waste space on native title bar, if qwebengineview can made work frameless window i'd know how.


mainwindow.h:

#include <qtwidgets> #include <qtoolbar>  class mainwindow : public qmainwindow {     q_object public:     mainwindow(); protected:     void showevent(qshowevent *event) q_decl_override;     bool nativeevent(const qbytearray &eventtype, void *message, long *result) q_decl_override; private:     qtoolbar *titlebar; }; 

mainwindow.cpp:

#include <qtwidgets> #include <qlabel> #include <qwebengineview> #include <windows.h> #include <windowsx.h> #include "mainwindow.h"  mainwindow::mainwindow() : qmainwindow() {     setwindowflags(windowflags() | qt::framelesswindowhint);     titlebar = addtoolbar(tr("title bar"));     titlebar->seticonsize(qsize(16, 16));     titlebar->setfloatable(false);     titlebar->setmovable(false);     titlebar->setstylesheet("qtoolbar { background: red; border: 0; padding: 0; }");     titlebar->addwidget(new qlabel("title bar", titlebar));     // try qlabel...     qlabel *central = new qlabel("hello world");     // ...or qwebengineview     //qwebengineview *central = new qwebengineview(this);     //central->load(qurl("http://www.google.com"));     setcentralwidget(central);     resize(320, 240); }  bool mainwindow::nativeevent(const qbytearray &eventtype, void *message, long *result) {     q_unused(eventtype);     msg *msg = (msg *)message;     hwnd hwnd = isvisible() ? (hwnd)winid() : null;     lparam lparam = msg->lparam;     const long border_width = 4;     rect winrect;     long x, y;     switch (msg->message) {     case wm_nccalcsize:         result = 0;         return true;     case wm_nchittest:         getwindowrect(hwnd, &winrect);         x = get_x_lparam(lparam);         y = get_y_lparam(lparam);         if (x >= winrect.left && x < winrect.left + border_width &&             y < winrect.bottom && y >= winrect.bottom - border_width)             *result = htbottomleft;         else if (x < winrect.right && x >= winrect.right - border_width &&             y < winrect.bottom && y >= winrect.bottom - border_width)             *result = htbottomright;         else if (x >= winrect.left && x < winrect.left + border_width &&             y >= winrect.top && y < winrect.top + border_width)             *result = httopleft;         else if (x < winrect.right && x >= winrect.right - border_width &&             y >= winrect.top && y < winrect.top + border_width)             *result = httopright;         else if (x >= winrect.left && x < winrect.left + border_width)             *result = htleft;         else if (x < winrect.right && x >= winrect.right - border_width)             *result = htright;         else if (y < winrect.bottom && y >= winrect.bottom - border_width)             *result = htbottom;         else if (y >= winrect.top && y < winrect.top + border_width)             *result = httop;         else if (titlebar->undermouse())             *result = htcaption;         else             break;         return true;     }     return qmainwindow::nativeevent(eventtype, message, result); }  void mainwindow::showevent(qshowevent *event) {     q_unused(event);     hwnd hwnd = (hwnd)winid();     dword newstyle = ws_popup | ws_caption | ws_thickframe | ws_maximizebox | ws_minimizebox;     setwindowlongptr(hwnd, gwl_style, static_cast<long>(newstyle));     setwindowpos(hwnd, 0, 0, 0, 0, 0, swp_framechanged | swp_nomove | swp_nosize);     showwindow(hwnd, sw_show); } 

main.cpp:

#include <qtwidgets> #include "mainwindow.h"  int main(int argc, char *argv[]) {     qapplication app(argc, argv);     mainwindow *window = new mainwindow();     window->show();     return app.exec(); } 

example.pro:

qt += core gui widgets webenginewidgets msvc:libs += -luser32 template = app sources += main.cpp \            mainwindow.cpp headers += mainwindow.h 


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -