How to make a round corner for the qwebengineview?
-
I just used the code like below that:
qwebengineview->setStyleSheet("QWidget{border-radius:12px;}");but the corner of the webview is still the rectangle.
even though I put the webview into a new qwidget.the style still the same. -
I've just tried what u mentioned.but failed.the qwebengineview is still the rectangle.
-
I've just tried what u mentioned.but failed.the qwebengineview is still the rectangle.
@nicker-player I don't think you tried what I mentioned, because there is nothing to "fail".
-

QWidget * t_widget = new QWidget(); t_widget->setFixedSize(180,80); t_widget->setStyleSheet("QWidget{border:1px solid red;border-radius:12px;}"); QWebEngineView * t_view = new QWebEngineView(t_widget); t_view->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); t_view->load(QUrl("https://forum.qt.io/"));like this ?the border of the qwebengine dosnt fit the corner outside.
-

QWidget * t_widget = new QWidget(); t_widget->setFixedSize(180,80); t_widget->setStyleSheet("QWidget{border:1px solid red;border-radius:12px;}"); QWebEngineView * t_view = new QWebEngineView(t_widget); t_view->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); t_view->load(QUrl("https://forum.qt.io/"));like this ?the border of the qwebengine dosnt fit the corner outside.
@nicker-player So this is what you call "into the widget"? Why don't you use layout? How would you expect qwebengineview to fit in the widget? And maybe adjust the margins to make sure the borders are shown (might not necessary), or use qframe. I think you are not a beginner since I often see you post here.
-
@nicker-player So this is what you call "into the widget"? Why don't you use layout? How would you expect qwebengineview to fit in the widget? And maybe adjust the margins to make sure the borders are shown (might not necessary), or use qframe. I think you are not a beginner since I often see you post here.
@Bonnie
In fact.Ive tried to use the layout to fit the widget.but it dosent work too.QWidget * t_widget = new QWidget(); t_widget->setFixedSize(180,80); t_widget->setStyleSheet("QWidget{border:1px solid red;border-radius:12px;background:transparent;}"); QHBoxLayout * t_layouttmp = new QHBoxLayout(t_widget); //t_layouttmp->setContentsMargins(0,0,0,0); //evne though i added the code here .the qwebengineview is still the rectangle. QWebEngineView * t_view = new QWebEngineView(); t_view->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); t_view->load(QUrl("https://forum.qt.io/")); t_layouttmp->addWidget(t_view); t_widget->setLayout(t_layouttmp);
-
@Bonnie
In fact.Ive tried to use the layout to fit the widget.but it dosent work too.QWidget * t_widget = new QWidget(); t_widget->setFixedSize(180,80); t_widget->setStyleSheet("QWidget{border:1px solid red;border-radius:12px;background:transparent;}"); QHBoxLayout * t_layouttmp = new QHBoxLayout(t_widget); //t_layouttmp->setContentsMargins(0,0,0,0); //evne though i added the code here .the qwebengineview is still the rectangle. QWebEngineView * t_view = new QWebEngineView(); t_view->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); t_view->load(QUrl("https://forum.qt.io/")); t_layouttmp->addWidget(t_view); t_widget->setLayout(t_layouttmp);
-
@Bonnie
In fact.Ive tried to use the layout to fit the widget.but it dosent work too.QWidget * t_widget = new QWidget(); t_widget->setFixedSize(180,80); t_widget->setStyleSheet("QWidget{border:1px solid red;border-radius:12px;background:transparent;}"); QHBoxLayout * t_layouttmp = new QHBoxLayout(t_widget); //t_layouttmp->setContentsMargins(0,0,0,0); //evne though i added the code here .the qwebengineview is still the rectangle. QWebEngineView * t_view = new QWebEngineView(); t_view->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); t_view->load(QUrl("https://forum.qt.io/")); t_layouttmp->addWidget(t_view); t_widget->setLayout(t_layouttmp);
@nicker-player Try to set margins in the layout to 0
-
if i used the code
t_layouttmp->setContentsMargins(0,0,0,0);the qwebengineview would block the border of the widget.then the whole widget view became the rectangle too.which looks like below.the qwebengineview is on the widget,but not in the widget.

I just want to make the qwebengineview to be a round corner without changing the background of the html body. -
@nicker-player So this is what you call "into the widget"? Why don't you use layout? How would you expect qwebengineview to fit in the widget? And maybe adjust the margins to make sure the borders are shown (might not necessary), or use qframe. I think you are not a beginner since I often see you post here.
@Bonnie said in How to make a round corner for the qwebengineview?:
I think you are not a beginner since I often see you post here.
Your faith in people on the internet is flattering :))
Just because someone posts frequently it doesn't necessarily mean he/she is good :)@nicker-player said in How to make a round corner for the qwebengineview?:
I just want to make the qwebengineview to be a round corner without changing the background of the html body.
That does not work like this.
The rendered webengine content is (and will be) still rectangular. So if you "cut" the corners of the containing/parent widget, you get exactly what you have above.Unfortunately I don't have a solution how to make the webengineview page itself a rounded rect (if this is what you are really after)
And I don't know if it is possible at all... -
if i used the code
t_layouttmp->setContentsMargins(0,0,0,0);the qwebengineview would block the border of the widget.then the whole widget view became the rectangle too.which looks like below.the qwebengineview is on the widget,but not in the widget.

I just want to make the qwebengineview to be a round corner without changing the background of the html body.@nicker-player So here you need to know that the border of stylesheet follows the box model:

When you have round corner borders, there will always need some space between the content area and the drawn borders, this is just how stylesheet works.

Suppose we do not use qwebengineview here, but a class supports stylesheet, for example
QLabel, with stylesheet {border:1px solid red;border-radius:12px;}, it will also show just like in your post.

In order to show the 12px-radius corner, we must leave some padding for 3-4px: {border:1px solid red;border-radius:12px; padding: 3px;} then it will show like this:

So since qwebengineview doesn't apply stylesheet, by using a parent qwidget and layout, we just make it behave like normal stylesheet (the contents margins of the layout act as the padding).
If your content area (qwebengineview) has single color background, you can make the round corner borders look seamless to the content by setting same background color in the stylesheet.

But if it is not that simple to set by stylesheet, then stylesheet is not the proper approach for you.@Pl45m4 said in How to make a round corner for the qwebengineview?:
Just because someone posts frequently it doesn't necessarily mean he/she is good :)
I wasn't expecting good, these are just basics...
-
@nicker-player So here you need to know that the border of stylesheet follows the box model:

When you have round corner borders, there will always need some space between the content area and the drawn borders, this is just how stylesheet works.

Suppose we do not use qwebengineview here, but a class supports stylesheet, for example
QLabel, with stylesheet {border:1px solid red;border-radius:12px;}, it will also show just like in your post.

In order to show the 12px-radius corner, we must leave some padding for 3-4px: {border:1px solid red;border-radius:12px; padding: 3px;} then it will show like this:

So since qwebengineview doesn't apply stylesheet, by using a parent qwidget and layout, we just make it behave like normal stylesheet (the contents margins of the layout act as the padding).
If your content area (qwebengineview) has single color background, you can make the round corner borders look seamless to the content by setting same background color in the stylesheet.

But if it is not that simple to set by stylesheet, then stylesheet is not the proper approach for you.@Pl45m4 said in How to make a round corner for the qwebengineview?:
Just because someone posts frequently it doesn't necessarily mean he/she is good :)
I wasn't expecting good, these are just basics...