Skip to main content
19 votes
Accepted

Make QGIS python plugin for both versions 2.x and 3.x?

Documentation Here you can find what is new and what is break under the PyQGIS API. To get details about how to port Python2 to Python3 go there You can find some detail about testing from QGIS2 to ...
Hugo Roussaffa's user avatar
13 votes
Accepted

QComboBox multiple selection - PyQT5

For anyone interested, here is an implementation of a CheckableComboBox. class CheckableComboBox(QComboBox): # Subclass Delegate to increase item height class Delegate(QStyledItemDelegate): ...
Yoann Quenach de Quivillic's user avatar
13 votes
Accepted

NameError: name 'QMessageBox' is not defined

This is a bug in NNJoin plugin. Open NNJoin_gui.py file located in "/Users/joanlee/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/NNJoin/" using an editor. Add ...
Noura's user avatar
  • 3,439
10 votes

PyQt signal when layer name is changed in PyQGIS

Use the nameChanged signal of QgsLayerTreeNode class. from qgis.core import QgsProject def name_changed(node, name): print(f"New Name: {name}") QgsProject.instance().layerTreeRoot()...
Kadir Şahbaz's user avatar
9 votes
Accepted

Using a custom UI for a QGIS processing algorithm script

I don't see the practical side of creating classes inside other classes. Just split it. Below is how I will make your code work : import os from PyQt5 import uic from PyQt5.QtWidgets import QWidget ...
J. Monticolo's user avatar
  • 15.9k
8 votes
Accepted

QGIS ImportError: No module named 'PyQt5.QtSvg'

You're missing the python3-pyqt5.qtsvg dependency. Install that and retry.
ndawson's user avatar
  • 27.8k
8 votes
Accepted

Opening embedded canvas in new window with all layers

Review this script. It creates a new QMainWindow and moves the existing map canvas to that window. I've made some changes. Firstly, add a file path (to QgsVectorLayer) to be displayed in map canvas. ...
Kadir Şahbaz's user avatar
8 votes
Accepted

Getting point geometry by clicking at the map within QGIS plugin

Change super(self, QgsMapTool).__init__(self, canvas) to super(QgsMapTool, self).__init__(canvas)
Kadir Şahbaz's user avatar
7 votes
Accepted

Emitting signal when project property is changed using PyQGIS

Yes, there is a way. It's the customVariablesChanged signal from QgsProject. def my_slot(): print("A project variable was just changed!") QgsProject.instance().customVariablesChanged....
Germán Carrillo's user avatar
7 votes
Accepted

Counting seconds using QTimer in PyQGIS

For what you are trying to do, QTimer.singleShot() is not really what you want. I would suggest setting an interval, then connecting your slot function to the timeout signal of QTimer and calling ...
Ben W's user avatar
  • 22.6k
6 votes
Accepted

Compatibility PyQt5 and PyQt4

I'm assuming when you say "PyQt5", you mean you are using QGIS 3.x. In which case: layer.pendingFields() becomes: layer.fields() And: layer = QgsMapLayerRegistry.instance().mapLayersByName('...
Joseph's user avatar
  • 76.1k
6 votes
Accepted

How to put QgsCheckableComboBox() into standby

You can add the combobox to a dialog window. After closing the dialog, print prints the selected items. from qgis.PyQt import QtGui from qgis.core import * planet_list = ["Venus", "...
Kadir Şahbaz's user avatar
6 votes

Developing QGIS plugin: AttributeError: object has no attribute

In new_mmqgis.py: You set self.first_start = True in initGui, then, you set self.first_start = False in run method. In geocode_web_service method, you are checking if self.first_start == True. That if ...
Kadir Şahbaz's user avatar
5 votes
Accepted

No custom widgets in Qt Designer for QGIS 3

The environment and path needs to be set for Qt Designer to access the QGIS Custom widgets. These can be set by running the "qgis-designer.bat" file that comes with a QGIS installation. For a ...
Philip Whitten's user avatar
5 votes

No custom widgets in Qt Designer for QGIS 3

In QGIS 3.2.0, custom widgets seem to be available: Tested on Windows 7 64-bit. Edit: I used the QGIS Standalone Installer Version 3.2 (64 bit) and following the simple on-screen instructions. Once ...
Joseph's user avatar
  • 76.1k
5 votes

How to get the selected value in a value map with Function Editor in QGIS 3.0.2?

You need to connect your LIVSMILJO comboBox to a signal and return the current text of LIVSMILJO comboBox every time selection of text changes in LIVSMILJO comboBox.This can be done as follows def ...
Asad Abbas's user avatar
  • 1,634
5 votes
Accepted

QPSQL driver on kubuntu 18.04

Solved by installing the library libqt5sql5-psql sudo apt install libqt5sql5-psql
Lennert De Feyter's user avatar
5 votes
Accepted

Get xy coordinates of QgsMapCanvas in PyQGIS 3?

You don't need to define lambda function and to specify self.canvas.scale() and self.canvas.xyCoordinates(). Because scaleChanged event passes scale and xyCoordinates passes coordinates to the related ...
Kadir Şahbaz's user avatar
5 votes
Accepted

QGIS2 to QGIS3 plugin migration issue AttributeError: type object 'QObject' has no attribute 'connect'

With this documentation about PyQt5 signals, try this : self.buttonBox.accepted.connect(Configuration.accept) self.buttonBox.rejected.connect(Configuration.reject)
J. Monticolo's user avatar
  • 15.9k
5 votes
Accepted

Displaying QgsMessageBar from plugin

I don't know how to do that in Qt Designer, but in PyQGIS directly, it is an easiest way : my_dlg = QDialog() my_dlg.resize(500, 300) my_dlg_lyt = QVBoxLayout(my_dlg) my_msg_bar = QgsMessageBar(my_dlg)...
J. Monticolo's user avatar
  • 15.9k
5 votes

PyQGIS: Querying PostGIS Table

As you have specified the geometry column (geom) in uri.setDataSource(), you need to select the geom column along with the id_ruas column. nb = 1050130 fields = 'id_ruas, geom' -- include geom in ...
Matt's user avatar
  • 17.7k
4 votes
Accepted

Problem running PyQt code in Qgis3

In QGIS you can't use an application object, because qgis itself is a QtApplication. Try to execute lines 6-10 alone and you'll see a widget on the screen. To have a full functional dialog, you'll ...
Andreas Müller's user avatar
4 votes
Accepted

How to open and add SQLite connection to browser with PyQgis

I have found an answer: con = ['name_of_db','C:\\path_to_db\\andorra.sqlite'] QSettings().setValue("SpatiaLite/connections/%s/sqlitepath" %(con[0]), con[1]) iface.reloadConnections() This code will ...
BearHunt's user avatar
  • 459
4 votes
Accepted

QGIS plugin mouseClickEvent

This is really more of a IT/ PyQt question, so I will provide an answer in the context of QGIS plugin development, to try to keep on topic. The reason your mousePressEvent does nothing is that you ...
Ben W's user avatar
  • 22.6k
4 votes
Accepted

Hook two horizontal slider each other - PyQt5

Test-it in another method like that : def run (self): self.dlg = Dialog() self.dlg.horizontalSlider.sliderMoved.connect(lambda v: self.adjust_sliders(1, v)) self.dlg.horizontalSlider_2....
J. Monticolo's user avatar
  • 15.9k
4 votes

NameError: name 'QMessageBox' is not defined

You should import QMessageBox from PyQt from qgis.PyQt.QtWidgets import QMessageBox
meteergen's user avatar
  • 375
4 votes

Efficient filtering of many options in QGIS Plugin

Perhaps you could loop through the checkboxes, using the isChecked() method to ascertain whether they are checked and if so, set all combobox items to checked. Then eventually, get all the checked ...
Matt's user avatar
  • 17.7k
4 votes
Accepted

Using pyqtSignal in emitting signal for maptool in QGIS

You just forgot to add self as the first argument of your onMapClick() method. The class instance object needs to be the first argument of all class methods. The canvasClicked() signal also emits the ...
Ben W's user avatar
  • 22.6k
4 votes
Accepted

"TypeError: disconnect failed beetween 'accepted' and 'save'" error when creating custom feature form with PyQGIS

I concur that there seems to be an issue with disconnecting the save() and resetValues() slots from the accepted and rejected signals of the QDialogButtonBox of QgsAttributeForm. Indeed, perusing the ...
Ben W's user avatar
  • 22.6k
4 votes

QgsFileWidget mandatory field in QWizard issue

Try to pass the third parameter as string which refers property name, filePath here. self.wizardPage.registerField('projPath*', self.projPath, 'filePath', self.projPath.fileChanged) Here is a working ...
Kadir Şahbaz's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible