Skip to main content
14 votes

QGIS plugin: Problems importing resources (resources_rc) file - plugin doesn't load - PATH problems?

You can avoid having to edit the .ui file or compiling, etc by doing the following: import sys sys.path.append(os.path.dirname(__file__)) FORM_CLASS, _ = uic.loadUiType(os.path.join( os.path....
Jason Hight'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
11 votes
Accepted

Adding a Tiles/wms? (openStreetMap) layer with python in QGIS

Tiles/WMS sources give you raster data. So, you have to use QgsRasterLayer() instead of QgsVectorLayer(). Try in this way: ... rlayer = QgsRasterLayer(urlWithParams, 'OpenStreetMap', 'wms') # ...
Kadir Şahbaz's user avatar
9 votes
Accepted

Work around for “Couldn’t load PyQt” error with QGIS 3.0.3 on Ubuntu 18.04?

I was able to reproduce this error by installing PyQt5 using the Python package manager. If you remove the Python-managed PyQt5 and instead install the OS version, QGIS should launch. I have confirmed ...
Lee Hachadoorian's user avatar
9 votes
Accepted

How to fix 'Could not find the Qt platform plugin “Windows” in “”' when implementing qgis in custom Python3 application?

Add the following environment variables at the beginning of your python script before loading qgis.core: #modify environment variables to find qgis and qt plugins during qgis.core import os.environ['...
Matt Brauer's user avatar
8 votes
Accepted

Opening Plugin with another Plugin

For my example, I took the QGIS plugin Plugin Builder 3 (link). After install of this plugin, a new repository is made in : \QGIS\QGIS3\profiles\default\python\plugins\pluginbuilder3 (here is the ...
J. Monticolo's user avatar
  • 15.8k
7 votes
Accepted

How to show only postgres vector layers in a QgsMapLayerComboBox?

In QGIS 2.x you'd need to pass a list of layers not coming from PostgreSQL: excepted = [] for layer in QgsMapLayerRegistry.instance().mapLayers().values(): if hasattr(layer, 'providerType') and ...
Germán Carrillo's user avatar
7 votes

How to use QT QGis custom widget in a plugin?

To properly use QT QGis custom widgets: Use imports such as: from PyQt4.QtGui import QDialog from qgis.gui import QgsFileWidget You must also edit the xx_dialog_base.ui file, to ensure that the ...
Bruno von Paris's user avatar
7 votes
Accepted

Connecting signals to different functions based on combobox selection

Instead of making individual connections for each combobox options, it is more reasonable to connect the button click event to one function which checks the combobox value and calls the related ...
Kadir Şahbaz's user avatar
7 votes
Accepted

PyQGIS Contour Labelling

Perhaps you will have more success working directly with the QgsPalLayerSettings class. The snippet below works for me on a contour layer generated with gdal_contour. vlayer = iface.activeLayer() ...
Ben W's user avatar
  • 21.9k
6 votes
Accepted

Keep UI Settings for a QGIS plugin

Right, you need to use QSettings to store values across QGIS sessions. QSettings is multi-platform, so you don't need to worry about where it stores the data on Linux, on Windows, or on Mac, it ...
Germán Carrillo's user avatar
6 votes

How to use Threads in PyQgis, mainly to keep UI active?

Use processing in QGIS 3.x In QGIS 3.x there is an infrastructure in place to have things running in threads. Processing is a good candidate to be what you are looking for when doing "heavy ...
Matthias Kuhn's user avatar
6 votes

Usage of QgsTask and QgsTaskManager

There's a typo in that script - it should be isCanceled() (one l, not two) You should also add your task to the global task manager instead of creating a new manager: QgsApplication.taskManager()....
ndawson's user avatar
  • 27.8k
6 votes
Accepted

Connecting Qt GUI to python code in QGIS Plugin

Your "check boxes" don't work because you're putting your lines in the wrong place (run method). However, you need first to declare objects in __init__ method for connecting them to a 'change_status' ...
xunilk's user avatar
  • 30k
6 votes
Accepted

Making a Feature Form for a standalone PyQGIS application as in QGIS

The following script generates a simple form. You can use it in your standalone PyQGIS application to display attributes for a given feature. You can also specify fields to be displayed (or not to be ...
Kadir Şahbaz's user avatar
6 votes
Accepted

Capturing CTRL+Key In KeyPressEvent in PyQGIS QgsMaptool

QKeyEvent has a method modifiers(). You should use it. def keyPressEvent(self, event): if event.modifiers() & Qt.ControlModifier: if event.key() == Qt.Key_R: print("...
Kadir Şahbaz's user avatar
6 votes
Accepted

Display a progressBar and use the execution time of several functions in QGIS plugin

Add a variable to the first function to store starting time. For example (self.start). Define a new function to set progress. Then use that function instead of setValue in other functions called by ...
Kadir Şahbaz's user avatar
6 votes
Accepted

What is QDomNode and QDomDocument in terms of PyQGIS?

Here is what QDomNode and QDomDocument are in the Qt context: The QDomDocumentclass represents the entire XML document. Conceptually, it is the root of the document tree, and provides the primary ...
Kadir Şahbaz's user avatar
5 votes
Accepted

Find out if checkbox checked - pyqgis

You can simply write something like: if self.dlg.myCheckBox.isChecked(): doSomething() else: doSomethingElse() Note that if you want something more dynamic (ie perform an action everytime the ...
ArMoraer's user avatar
  • 5,659
5 votes

Properter to get travel time as cost for network analysis

Here's a short Properter which I'm working on that might provide part of the answer. It aims to modify shortest path calculations for a road network by excluding freeways (because I'm using it for ...
Steve's user avatar
  • 361
5 votes

PyQGIS plugin doesn't work layer list combo box

Don't make your own - PyQGIS has a whole library of standard reusable widgets like this. In this case use QgsMapLayerComboBox. All the hard work is done for you, it's stable and unit tested, and will ...
ndawson's user avatar
  • 27.8k
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

QGIS plugin: set the position of the featureForm

I found the solution, I used: virtual QgsAttributeDialog* QgisInterface::getFeatureForm ( QgsVectorLayer * l, QgsFeature & f ) Returns a feature form for a given feature. ...
ncica's user avatar
  • 942
5 votes
Accepted

How to add DockWidget above the Layer panel using PyQGIS

You can re-add the Layers Panel which would place it below any existing panels: from qgis.PyQt.QtCore import Qt from qgis.PyQt.QtWidgets import QApplication from PyQt4.QtGui import QDockWidget iface....
Joseph's user avatar
  • 76k
5 votes
Accepted

PyQt5 QGIS Plugin - "native Qt signal is not callable" error

The problem is how you are trying to interact with the signal. Instead of checking for a signal with a conditional 'if:' statement, you should listen for it and connect it to a slot. the basic idea (...
Ben W's user avatar
  • 21.9k
5 votes
Accepted

Image Adding Problem to QGIS Plugin GUI with Qt Designer

I found a solution with the help of this post. It worked for me. I'm on QGis 3.16, I hope it's the same for the 3.10 version. Once you've added the resource image. You need to open the file ...
JULESG's user avatar
  • 1,637
5 votes
Accepted

Using PyQt in PyQGIS inside QGIS 3.16

I think the original code have a different indentation : import sys from PyQt5 import QtWidgets def window(): app = QtWidgets.QApplication(sys.argv) w = QtWidgets.QWidget() b = QtWidgets....
J. Monticolo's user avatar
  • 15.8k
5 votes
Accepted

PyQT plugin window is always smaller than when run in QGIS

Simply dragging and dropping widgets onto a dialog in Qt Designer is a quick way to get a working ui, but it does not in any way guarantee consistent appearance. To demonstrate this, I created a dummy ...
Ben W's user avatar
  • 21.9k
5 votes
Accepted

Collapsing legend in ToC via PyQGIS

I have found solution, but it looks silly. Layer after added has isExpanded value set to False even though in ToC appears to be expanded. By setting status of node to True then to False it takes ...
vealen's user avatar
  • 133
5 votes
Accepted

Disabling automatic selection in QgsMapLayerComboBox

Use this for all QgsMapLayerComboBox. maplayercombobox.setAllowEmptyLayer(True) maplayercombobox.setCurrentIndex(0) If you set an index after using setAllowEmptyLayer(True), since combobox has a ...
Noura's user avatar
  • 3,429

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