release 3.2: Qt6/QGIS 4 support and bug fixes#25
Conversation
|
The I could get the code of this PR to run on my machine; however, there was an issue with # (line 26)
from qgis.PyQt.QtGui import QIcon, QFontMetrics
# (line 309)
idealWidth = QFontMetrics(QApplication.instance().font()).horizontalAdvance(txt) Here is the traceback: AttributeError: 'QApplication' object has no attribute 'fontMetrics'
Traceback (most recent call last):
File "/QGIS/QGIS4/profiles/default/python/plugins/changeDataSource/changeDataSource.py", line 421, in run
self.populateLayerTable()
~~~~~~~~~~~~~~~~~~~~~~~^^
File "/QGIS/QGIS4/profiles/default/python/plugins/changeDataSource/changeDataSource.py", line 244, in populateLayerTable
self.dlg.layerTable.setCellWidget(lastRow, 0, self.getLabelWidget(layer.id(), 0, style=cellStyle))
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/QGIS/QGIS4/profiles/default/python/plugins/changeDataSource/changeDataSource.py", line 309, in getLabelWidget
idealWidth = QApplication.instance().fontMetrics().horizontalAdvance(txt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'QApplication' object has no attribute 'fontMetrics'
Python version: 3.14.5 (main, May 10 2026, 18:26:20) [GCC 16.1.1 20260430]
QGIS version: 4.0.2-Norrköping Norrköping, exportedApart from this small change, the PR worked with the versions indicated above. 🥳 |
falkmielke
left a comment
There was a problem hiding this comment.
(see comment on #25 ; these suggestions are the adjustments which worked for me to get the plugin running)
| import os.path | ||
|
|
||
| from qgis.PyQt.QtCore import QSettings, QTranslator, QCoreApplication, Qt, pyqtSignal | ||
| from qgis.PyQt.QtGui import QIcon |
There was a problem hiding this comment.
for fontMetrics to be used (below), I would suggest to add QFontMetrics:
from qgis.PyQt.QtGui import QIcon, QFontMetrics
| edit = QLineEdit(parent = self.dlg.layerTable) | ||
| idealWidth = QApplication.instance().fontMetrics().width(txt) | ||
| edit = QLineEdit(parent=self.dlg.layerTable) | ||
| idealWidth = QApplication.instance().fontMetrics().horizontalAdvance(txt) |
There was a problem hiding this comment.
This gives an error on the (almost) latest versions of QGIS and Python: fontMetrics have to be turned into an object QFontMetrics. The following worked for me:
idealWidth = QFontMetrics(QApplication.instance().font()).horizontalAdvance(txt)| edit = QLineEdit(parent = self.dlg.layerTable) | ||
| idealWidth = QApplication.instance().fontMetrics().width(txt) | ||
| edit = QLineEdit(parent=self.dlg.layerTable) | ||
| idealWidth = QApplication.instance().fontMetrics().horizontalAdvance(txt) |
There was a problem hiding this comment.
| idealWidth = QApplication.instance().fontMetrics().horizontalAdvance(txt) | |
| idealWidth = QFontMetrics(QApplication.instance().font()).horizontalAdvance(txt) |
| import os.path | ||
|
|
||
| from qgis.PyQt.QtCore import QSettings, QTranslator, QCoreApplication, Qt, pyqtSignal | ||
| from qgis.PyQt.QtGui import QIcon |
There was a problem hiding this comment.
| from qgis.PyQt.QtGui import QIcon | |
| from qgis.PyQt.QtGui import QIcon, QFontMetrics |
|
Thanks @falkmielke! Applied your QFontMetrics fix and bumped to 3.2.1 (commit a9dac49). |
release 3.2: Qt6/QGIS 4 support, native setDataSource, SQL view & provider fixes
preserves auxiliary storage (manual label positions, data-defined overrides)
and clears layer tree warning/memory indicators after reload
memory layer fields now string(0) unlimited instead of string(250)
wcs, arcgismapserver, xyz (raster)
Python 2 / PyQt4 shims, unused resources_rc import