Hot answers tagged

24

You can add a custom menu to the QGIS GUI this way: self.menu = QMenu( "&My tools", self.iface.mainWindow().menuBar() ) actions = self.iface.mainWindow().menuBar().actions() lastAction = actions[-1] self.iface.mainWindow().menuBar().insertMenu( lastAction, self.menu ) As you can see in the code snippet above, you are adding a menu to the second to last ...


11

According to the official Road Map Qgis 3.0 was released on 2018-02-23. The first Long Term Support 3.x release will be version 3.4 on 2018-10-26.


8

Here is a good tutorial that helped me a lot: http://pythongisbook.com/blog/2013/04/11/creating-a-postgresql-connection-from-a-qgis-layer-datasource/ update The above link has expired... :( Here is my code that I use in my QGIS plugin: from PyQt4.QtSql import * db = QSqlDatabase('QPSQL') if db.isValid(): # string db.setHostName('your_host') # ...


8

It's possible without using a python function, with a little bit of hacks: minute( age( todatetime('2000-01-01 10:18:00'), todatetime(2000-01-01 10:16:30') ) ) will return "1.5". To break it down, "age" returns the difference between two datetimes as an interval type. This needs to be wrapped in the "minute" function to extract the length of this interval ...


7

For OpenSource GIS tech investigate the offereings available via OsGeo. This is not the only source of FOSS4G but is a comprehensive stable of solutions that work well together and, in some cases, are the test bed for certain GIS standards. QGIS is an excellent solution for your needs as it has both desktop and server solutions but also comes bundled with ...


7

In the meanwhile I found a solution, maybe a workaround for my app to show a legend with only parts of the layers drawn on the map canvas. For the interested audience I want to give a summary. Adding maplayers to mapLayerRegistry, automatically builds a maplayerTree, when parameter addToLegend remains True. I set it to False, to build a layer tree with ...


7

In this case, layer is an instance of QgsVectorLayer, because currentLayer gives you that. But ogr.Open() needs a path. So you need to get layer source to pass to ogr.Open(). QgsVectorLayer class has source method which gives you full path of the layer source. Use in that way: layer = self.dlg.mMapLayerComboBox.currentLayer() layer_path = layer.source() ...


6

Google Static map api requires centre,lat/lng and pixel size as well as zoom level This is a non-JavaScript version (but python) for working out the pixel dimensions. You will need to modify to suit your needs but the key point is that it contains CalculateBoundsZoomLevel Which take a cluster of points and calculate the zoom level and centre of the map ...


6

You can use a single call to setAttributes() in order to set all attribute values for a feature, i.e., no need to call it twice for the same feature. For instance, the following code sets 4 attribute values of a single feature at once: lyr = iface.activeLayer() feat = QgsFeature() feat.setAttributes( [0,"CAP","NUEVO","00000"] ) feat.setGeometry( ...


5

QGIS 2.10 and later can be compiled against Qt 5. Current QGIS master branch (which will become QGIS 3.0) requires Qt 5. That means: if you download QGIS from a known place and it is labeled with a version number below 2.99, you will be running it with Qt 4. If it is labeled with a version number 2.99 (or 3.X) you will be running it with Qt 5. Please note:...


5

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 ...


5

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....


5

It's a while ago I did this this the last time but as far as I remember you can use a resource-file http://doc.qt.io/qt-4.8/resources.html#resource-collection-files-op-op-qrc , add your image there, choose the image from this resource in qt-designer and compile the resources. Edit1: Screenshot added: Assign Image from ressources, not from file: Edit2: I ...


5

QGIS 2.xx python plugins depends on PyQT4 - so you need Qt4. Qt5 only let you use QGIS without python and is experimental. The future QGIS 3 will use PyQt5 and python3. See details about QGIS 3 in blogpost.


5

I've coded a simple QgsMessageBar which contains a widget with 3 double-spinbox (and their labels), and a QPushButton for load colors. One for each color (Blue, Orange and Red). Each SpinBox have a default value (0), a minimum (0), a maximum (100) and a step (0.5). These values can be easily edited in the code (in the BarWidget class). The messageBar pop ...


4

I found a workaround. I deleted all the data from the combobox in QT Designer and I defined the edit widget in Layer Properties -> Fields as Value Map. There, I put the data which I want displayed and voila!


4

One way would be to access you plugin from the Python Init function file defined under Layer Properties tab Fields that'a controlling your UI. Partly from The PyQGIS Programmers's Guide p. 114: if 'pinpoint' in qgis.utils.plugins: pp = qgis.utils.plugins['pinpoint'] pp.someMethodFromThePlugin


4

It is a QgsMapCanvas, which subclasses QGraphicsView. You can browse the source code for this class on github. There is some developer documentation to introduce this class in the PyQGIS cookbook. You can, of course, just re-use parts of QGIS, or enhance QGIS, rather than create your own application if you choose.


4

If you're using 2.8 or later, you can use the Python function builder. This code will do the calculation. I don't think you need to use Qt objects for this. from qgis.core import * from qgis.gui import * from datetime import datetime import time @qgsfunction(args=2, group='Python') def timedifference(values,feature,parent): ''' call this function ...


4

You want to style your layer based on three values and you want a quick way to change those values. One way to get something close would be to create a layer with no geometry and put the three values into it and then dock its Attribute table window. Create your style expression to get the values from the layer: WHEN "valdco" = attribute(get_feature('...


4

Change verstretch value from 0 to 1 for two QListWidgets. <widget class="QListWidget" name="list_projects"> <property name="sizePolicy"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <horstretch>0</horstretch> <verstretch>1</verstretch> <!-- change to 1--> </sizepolicy> ...


4

I just installed QGIS 3.10 for the first time on Windows and when I tried to run it with Python I got exactly the same error message. I fixed it by explicitly setting the QT_QPA_PLATFORM_PLUGIN_PATH environment variable. You can check if this is your problem too by running the following command in your Python script: import os print(os.environ['...


3

@Martin has provided excellent links in order to create plugins for QGIS. To make life a little easier, there is a plugin called Plugin Builder which very easily creates all the core files you need for your plugin. You can download and install this from the QGIS toolbar: There is also a tutorial here which describes how to use the Plugin Builder (coupled ...


3

I recommend you to read the qgis cookbook: http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/ There you can read how to program a plugin that suits your needs. In the section plugins: http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/plugins.html it is shown how to set up a plugin with a user interface that is using qt


3

QGIS 2.x uses QT4 and PyQT4. You can check this in the aboutbox. I don't believe you can use QT5 yet.


3

I've made Qt5-based QGIS on Windows successfully!! Download: https://github.com/chenguanzhou/QGIS-Windows-Build-Qt5-VS2015-x64/releases


3

but there aren't cpp files, and this is the reason that compilar is claiming. No. The reason your compiler (or rather linker) is complaining is that it's missing the symbols of the functions declared in the header files. You do not need the cpp files to develop with the QGIS library. What you need are the header files (for the includes) the library files ...


3

I found the right combination of the above mentioned items to make it possible for Qt to import Qgis libraries and build the app: Qt 4.8.6 for MSVC2010 Qt Creator 4.3.0 (from a Qt 5.9.0 installation). Qt Creator 3.0 may be used as well. Visual C++ express 2010 - Include Windows Kits/SDK in install OSGeo4W - Installed qgis-ltr-dev and all libraries Cmake 2.8....


3

QTextEdit is probably not the good Widget for you. Maybe you can try with something like QListWidget. You can use it as in this example:https://wiki.python.org/moin/PyQt/Adding%20items%20to%20a%20list%20widget 1 import sys 2 from PyQt4.QtGui import * 3 4 layers = self.iface.legendInterface().layers() 5 listWidget = self.dlg.yourQListWidget(...


3

If I understand you very well you can do an attribute table formatting using the following steps: Open you attribute table Use Conditional Formatting Rules Select the field the you want to apply the formatting rules from the drop-down list. In this example, I want to use a field name "Test" Select New Rule Select New expression, write the expression ...


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