This problem is caused by uic not working properly. I am not sure exactly why but I can show the symptoms and a workaround.
The initial plugin .ui file has an empty resources element:
When you edit the resources for the plugin in QtDesigner this changes to:
You can avoid having to edit the .ui file or compiling, etc by doing the following:
FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'test_dialog_base.ui'), resource_suffix='')
resource_suffix defaults to '_rc' which is why it's always looking for 'resources_rc.' (you can ...
It's not easy just to switch to QGIS if you've decided to stay invested in the Arc-Geodatabase. I would say don't switch. You'll have more trouble mixing the technologies than it would be worth.
The ESRI Geodatabase is a database meant to work with the ESRI platform. Although there is a 'plugin' for QGIS to use a file geodatabase, there is (as suggested ...
from PyQt4 import QtGui
reply = QMessageBox.question(self.iface.mainWindow(), 'Continue?',
'Your message here', QMessageBox.Yes, QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
#do something if yes
#do something if no
or in console:
from PyQt4 import QtGui
reply = QtGui.QMessageBox.question(...
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') # EDIT THIS LINE
layers = QgsMapLayerRegistry.instance().mapLayers().values()
for layer in layers:
if layer.type() == QgsMapLayer.VectorLayer and layer.geometryType() == QGis.Line:
self.dlg.ui.layerCombo.addItem( layer.name(), layer )
You can then get the layer from the combo like this:
index = self.dlg.ui.layerCombo.currentIndex()
layer = self.dlg.ui....
I finally fixed it after 3 hours of trying.
As someone said QT Designer adds
to your UI file. I simply deleted those rows and everything works fine (resources are visible in GUI)
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 that an OS-managed PyQt5 is available on clean install of Ubuntu 18.04, and a/o June 1, 2018, both Ubuntu repositories and PyPI are providing PyQt 5.10.1.
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['QT_QPA_PLATFORM_PLUGIN_PATH'] = r'~qgis directory\apps\Qt5\plugins'
os.environ['PATH'] += r';~qgis directory\apps\qgis\bin;~qgis directory\apps\Qt5\bin'
Do you have to publish it?
Legally, The GPL License of PyQGIS forces you to share the code only with your "client", therefore your company.
So No, you don't have to publish it. You can keep them internally, create your own repository, and share with who you want.
But note that whoever receives the code is allowed to pass it on by the terms of the GPL.
Use a custom form designed using Qt designer.
(I've been successful doing this on QGIS 2.6 on Windows, but my Linux QGIS version crashes. I'm writing this having worked things out for the first time so this answer may well benefit from corrections).
You should have the relationship set up in project properties. Choose the relations sub-menu and add a ...
Benefits for switching:
No license cost per user!
May integrate with other open source apps. (e.g. GeoServer, MapServer, PostGIS..etc)
Plug-in language built on C++/python (pyQGIS)
Not as buggy
Disadvantage for switching:
Learning curve for users and developers
Cannot edit File GDB data, will have to switch to PostgresSQL/PostGIS or SQLite DB
A good and user friendly way to do it is using the QgsMessageBar class.
A first look here by the author of this class:
and then an example of a progress bar can be obtained directly from the QGIS code (Processing core plugin)
Sorting layers is a particularly painful task in PyQGIS, because of the lack of suitable methods in the QgsLayerTreeNode class. Based on your code, I managed to write a console script that seems to work (after multiple tests...).
Disclaimer #1: backup your project before testing this script.
Disclaimer #2: this script only sorts 1st-level groups (I didn't ...
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 handles it for you.
You need to call QSettings in this way:
from PyQt4.QtCore import QSettings
settings = QSettings()
You can use QSettings() every time you need ...
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 layer.providerType() != 'postgres':
excepted.append( layer )
self.dlg.comboBox.setExceptedLayerList( excepted )
In QGIS 3.x you'll pass a list of ...
You can use QSettings to read and write settings. It takes care of storing the settings on all platforms without you having to find a place to write a file.
I used this functionality in the Google Maps Engine Connector plugin to store UI settings
Yes, you can store settings in separate files/ways with QSettings, and within the same Q(Core)Application. This makes it ideal for what you are looking to do.
When initializing your PyQGIS plugin's QSettings, you will want to do something like this for a standard settings setup:
my_settings = QtCore.QSettings(QtCore.QSettings.IniFormat,
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 computation" things. If you implement your algorithm as a processing algorithm, it will also be reusable by other code of yours.
Have a look at one of the many ...
Technically the only files you need for a plugin are:
All the other files are just extra stuff depending on what you plugin does. If you don't need any resources (which you normally do) then you don't need resources.rc.
On to your question:
Just hold a class that inherits from your generated ui ...
By using the new Layer tree (aka legend or Toc) added by Martin Dobias since QGIS v.2.4, you can load a layer to the bottom of the ToC following these steps:
Get a reference of the layer tree
root = QgsProject.instance().layerTreeRoot()
Create the layer object
mylayer = QgsVectorLayer("/Path/to/your/data.shp", "my layer", "ogr")
Add the layer to the QGIS ...
I'll answer the question that is stated in the title.
You can use the following code to show your dialog in the bottom-left corner (do all this right before the call to self.dlg.show()):
ph = self.dlg.parent().geometry().height()
px = self.dlg.parent().geometry().x()
py = self.dlg.parent().geometry().y()
dw = self.dlg.width()
dh = self....
If you are fine with a solution that uses QNetworkAccessManager from Qt (instead of the manager from QGIS libs), you can do it this way:
from datetime import datetime
from PyQt4.QtCore import QUrl
from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest
url = QUrl("http://www.geotux.tuxfamily.org")
request = ...
Should have searched a bit more (...) :
def __init__(self, iface):
canvas = iface.mapCanvas()
self.canvas = canvas
if e.button() == Qt.RightButton:
menu = QMenu()
quitAction = menu.addAction("AnyAction")...
You can move cursor like that:
from PyQt4.QtGui import *
from PyQt4.QtCore import *
cursor = QCursor()
It moves your cursor to point 100,200 in your screen. If you want to get coordinate of a point on the map canvas, you need to translate them:
# coordinates of point on map canvas
point = QPoint(100,100)
# translate widget ...
You probably want to implement a QgsMapTool and set this as the active map tool.
This offers several methods which you can implement to react
and some more
You will then have to do
canvas.setMapTool( yourmaptool )
to make it active.
If you really ...
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 cycling routes) and roads that haven't been built yet. In my road layer, these are CLASS_CODE 0 and 9.
The property() method calculates the weight allocated to ...
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 keep UI consistency with the rest of the QGIS interface.
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 widgets are imported from the python module and not from the C libraries (it seems there is a bug in the generation of this .ui file, see Plugins crashing with "...