浏览器透明设置例子,qt5.6才支持
用simpleBrowser例子的基础上,在BrowserWindow构造函数修改如下
BrowserWindow::BrowserWindow(QWidget *parent, Qt::WindowFlags flags)
: QMainWindow(parent, flags)
, m_tabWidget(new TabWidget(this))
, m_progressBar(new QProgressBar(this))
, m_historyBackAction(nullptr)
, m_historyForwardAction(nullptr)
, m_stopAction(nullptr)
, m_reloadAction(nullptr)
, m_stopReloadAction(nullptr)
, m_urlLineEdit(new UrlLineEdit(this))
{
//todo:test webpage transparent
{
QWidget *root = new QWidget(this);
root->setStyleSheet("background:red");
root->setAutoFillBackground(true);
setCentralWidget(root);
QWebEngineView* web = new QWebEngineView(root);
web->page()->setBackgroundColor(Qt::transparent);
web->setHtml("<html><head><style>"
"h1 {background-color: #00ff00;}</style></head>"
"<body><h1>This is heading 1</h1></body></html>",
QUrl("http://localhost"));
web->move(0, 0);
web->show();
return;
}