Matt
Matt

Reputation: 554

PySide 6: How to turn off QWebEngineView scrollbars?

I’m rendering a folium map on a pyside6 QWebEngineView, using setHtml().

I can set the size of the map frame in the folium map class at instantiation time. My problem is, even when the map is quite small, QWebEngineView presents the map in a larger frame, with a scrollbar.

I would like to render the map without a scrollbar. The base frame ought to be of proper size, so that there is no scrollbar. (The folium map can pan, zoom, etc. without changing size)

I’ve read the *View class doc, and the *Page doc and I can’t see a way to set the base page size or hide the scrollbar.

Has anyone encountered/solved this?

See example below.

class MyMap(qth.QWebEngineView):

    def __init__(self):
        super().__init__()
        self.setObjectName("my_map_plot")
        self.setAccessibleName("my_map_plot")
        self.width_px = self.width() - 24
        self.height_px = self.height()
        self.initial_tileset='cartodbdark_matter'
        self.map = folium.Map(location=[41.530, -70.679],zoom_start=14,tiles=self.initial_tileset, width=self.width_px,height=self.height_px)
        self.init_map()
        self.show()
    
    def init_map(self):
        # Add some alternate tile layers
        folium.TileLayer('cartodbpositron').add_to(self.map)
        folium.TileLayer('Stamen Terrain').add_to(self.map)
        folium.TileLayer('Stamen Toner').add_to(self.map)
        folium.TileLayer('Open Street Map').add_to(self.map)
   
        self.map.add_child(folium.LatLngPopup())
        whoi_marker_icon = folium.Icon(icon="globe",color="darkblue")
        folium.Marker([41.52417,-70.67151], icon=whoi_marker_icon,tooltip="WHOI", popup="Woods Hole Oceanographic Institution").add_to(self.map)
        # this should be last
        folium.LayerControl().add_to(self.map)  
          
    def show(self):
        map_html = self.map._repr_html_()
        # set the size of the web view
        self.setBaseSize(qtc.QSize(self.width_px,self.height_px))
        self.setHtml(map_html)

Upvotes: 0

Views: 238

Answers (1)

Matt
Matt

Reputation: 554

After more digging in the online docs, I found the API for page settings:

web_view.page().settings().setAttribute(PySide6.QWebEngineCore.QWebEngineSettings.WebAttribute.ShowScrollBars,False)

Upvotes: 0

Related Questions