如何将叶子地图包含到PyQt5应用程序窗口中?

如何将叶子地图包含到PyQt5应用程序窗口中?,第1张

如何将叶子地图包含到PyQt5应用程序窗口中?

这个问题与QWebEngineView或folium没有关系,但是如何在窗口内放置部件,如果是这样,那么一种解决方案是在这种情况下使用布局,我将使用以下结构:首先在此内部建立一个中央小部件QHBoxLayout,并在QHBoxLayout中将QWidget作为容器添加到左侧的QVBoxLayout(将放置按钮的位置)和QWebEngineView的右侧:

import ioimport sysimport foliumfrom PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgetsclass Window(QtWidgets.QMainWindow):    def __init__(self):        super().__init__()        self.initWindow()    def initWindow(self):        self.setWindowTitle(self.tr("MAP PROJECT"))        self.setFixedSize(1500, 800)        self.buttonUI()    def buttonUI(self):        shortPathButton = QtWidgets.QPushButton(self.tr("Find shortest path"))        button2 = QtWidgets.QPushButton(self.tr("Another path"))        button3 = QtWidgets.QPushButton(self.tr("Another path"))        shortPathButton.setFixedSize(120, 50)        button2.setFixedSize(120, 50)        button3.setFixedSize(120, 50)        self.view = QtWebEngineWidgets.QWebEngineView()        self.view.setContentsMargins(50, 50, 50, 50)        central_widget = QtWidgets.QWidget()        self.setCentralWidget(central_widget)        lay = QtWidgets.QHBoxLayout(central_widget)        button_container = QtWidgets.QWidget()        vlay = QtWidgets.QVBoxLayout(button_container)        vlay.setSpacing(20)        vlay.addStretch()        vlay.addWidget(shortPathButton)        vlay.addWidget(button2)        vlay.addWidget(button3)        vlay.addStretch()        lay.addWidget(button_container)        lay.addWidget(self.view, stretch=1)        m = folium.Map( location=[45.5236, -122.6750], tiles="Stamen Toner", zoom_start=13        )        data = io.BytesIO()        m.save(data, close_file=False)        self.view.setHtml(data.getvalue().depre())if __name__ == "__main__":    App = QtWidgets.QApplication(sys.argv)    window = Window()    window.show()    sys.exit(App.exec())



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5632458.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存