2

I have QBoxLayout with QWebEngineView widget

from PyQt6.QtWidgets import QApplication, QWidget, QBoxLayout
from PyQt6.QtWebEngineWidgets import QWebEngineView
from PyQt6.QtCore import QUrl

app = QApplication(["test"])
window = QWidget()
layout = QBoxLayout(QBoxLayout.Direction.TopToBottom, window)

view = QWebEngineView()
layout.addWidget(view)

view.setUrl(QUrl("URL"))

window.setFixedSize(700, 700)

window.setLayout(layout)
window.show()

app.exec()

I want to remove this little gap (marked with black lines) and place my layout to [0; 0] position

Gap

I tried view.setGeometry(QRect(0, 0, 700, 700)), but that doesn't work

NotEasy
  • 43
  • 5
  • 2
    Use `QVBoxLayout` instead of `QBoxLayout(direction)`, also the `window` argument already sets the layout for the widget, so calling `setLayout()` again is pointless. – musicamante May 09 '23 at 13:24

1 Answers1

1

The layout is placed in the top corner, but the layout places a margin arount its content. If you set this margin to 0 all around you get the desired result:

layout.setContentsMargins(0, 0, 0, 0)
mahkitah
  • 562
  • 1
  • 6
  • 19