简体   繁体   中英

how to set frame on top left and top right half of hight screen?

I want to set frame on top left and top right half of hight screen like this.

在此处输入图像描述

I try to set in this code.

web1 = QWebEngineView()
x=web1.width()*0.5
y=web1.height()*0.5
web1.setFixedSize(x,y)
web1.setGeometry(0,0, x, y)
web1.setWindowFlag(Qt.FramelessWindowHint)
web1.load(QUrl("https://www.google.com"))
web1.show()

web2 = QWebEngineView()
x=web2.width()
y=web2.height()
web2.setFixedSize(x,y)
web2.setGeometry(0,0, x, y)
web2.setWindowFlag(Qt.FramelessWindowHint)
web2.load(QUrl("https://www.facebook.com"))
web2.show()

It still show in top left. How to fix it?

If you want to place an element (QWebEngineView) with respect to another (the screen) then you must take both geometries as a reference, but you only use the first one and that's the cause of the problem.

The solution is:

from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets


if __name__ == "__main__":
    import sys

    app = QtWidgets.QApplication(sys.argv)

    rect_screen = app.primaryScreen().availableGeometry()

    web1 = QtWebEngineWidgets.QWebEngineView()
    web1.setFixedSize(0.5 * rect_screen.size())
    web1.setWindowFlag(QtCore.Qt.FramelessWindowHint)
    web1.setGeometry(
        QtWidgets.QStyle.alignedRect(
            QtCore.Qt.LeftToRight,
            QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop,
            web1.size(),
            rect_screen,
        )
    )
    web1.load(QtCore.QUrl("https://www.google.com"))
    web1.show()

    web2 = QtWebEngineWidgets.QWebEngineView()
    web2.setFixedSize(0.5 * rect_screen.size())
    web2.setWindowFlag(QtCore.Qt.FramelessWindowHint)
    web2.setGeometry(
        QtWidgets.QStyle.alignedRect(
            QtCore.Qt.LeftToRight,
            QtCore.Qt.AlignRight | QtCore.Qt.AlignTop,
            web2.size(),
            rect_screen,
        )
    )
    web2.load(QtCore.QUrl("https://www.facebook.com"))
    web2.show()

    sys.exit(app.exec_())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM