I’m trying to round the borders of a QWebEngineView widget, i have tried using stylesheet but the borders aint changing:
current
I modified the borders on photoshop to demonstrate what i’m trying to achieve:
desired
What else i could try?
#include <QtWidgets>
#include <QWebEngineView>
#include <QWebEngineScript>
#include <QWebEngineScriptCollection>
#include <QQuickWidget>
class Widget : public QWidget
{
Q_OBJECT
public:
QWebEngineView* view = nullptr;
Widget() : QWidget(nullptr)
{
QWidget* widget = new QWidget;
widget->setObjectName("webEngineWidget");
view = new QWebEngineView;
view->setUrl(QUrl("https://www.google.com"));
view->setAttribute(Qt::WA_StyledBackground);
view->setContentsMargins(32, 32, 32, 32);
view->page()->setBackgroundColor(Qt::transparent);
QQuickWidget* quickWidget = view->findChild<QQuickWidget*>();
quickWidget->setAttribute(Qt::WA_StyledBackground);
quickWidget->setContentsMargins(32, 32, 32, 32);
QGridLayout* layout = new QGridLayout(widget);
layout->setContentsMargins(32, 32, 32, 32);
layout->addWidget(view);
QHBoxLayout* mainLayout = new QHBoxLayout(this);
mainLayout->addWidget(widget);
setStyleSheet(R"(
#webEngineWidget
{
background-color: gray;
border: 4px solid red;
border-radius: 32px;
}
QWebEngineView
{
background-color: green;
border: 4px solid yellow;
border-radius: 32px;
}
QWebEnginePage
{
background-color: blue;
border: 4px solid green;
border-radius: 32px;
}
QQuickWidget
{
background-color: yellow;
border: 4px solid black;
border-radius: 32px;
}
)");
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
The borders are just to illustrate what the stylesheet is changing, the goal is to create a rounded widget that fits on our main window.
New contributor
Ahalya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.