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:
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 ...
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)
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.
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(...
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 ...
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)
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 ...
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 ...
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 ...
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
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'
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,
I suggest you to have a look at PyQt4 tutorials on Internet. They should help you understand how PyQt4 applications are structured, and should introduce you to the wide variety of widgets PyQt4 provides you with.
Just to cite some, here is a list of resources you could read:
Introduction to PyQt4
GUI - PyQt4
Once you've done that, you ...
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....
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")
action = menu.exec_(...
It's just a widget so you sure can. Normally you would add it to a layout however that will resize your canvas when it pops up which is a bit annoying IMO. What you can do is just some logic to resize the bar to match the parent size when it is shown.
Here is some code that I use to do just that:
def __init__(self, ...
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 ...
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.
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.
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
QGIS Vector Layer Class
You will need to become familiar with layer attributes and features. The QGIS Vector Layer Class Reference will be a good source of information.
The basic workflow will be to:
Select the layer via the QgsVectorLayer class
Get some or all features in the layer with the getFeatures()
Work with the feature geometry (...