0

When I am using the QGIS built-in formula to create a formula (for QField), I can use functions and access variables like now() or $y:

QGIS

How can I access them using Qt Designer?

I want to display the current time and position within a label:

Qt

1
  • There ist no code. I am not developing a plugin. I have an attribute table and integrate the UI file with a file dialog in QGis. I don't know where to add code, there is none.
    – noclueGIS
    Commented Aug 1, 2021 at 11:40

1 Answer 1

2

To do that, find the object name of the QLineEdit or QLabel. You can also set the object name on Qt Designer. For instance, if you want to set now() to an QLineEdit widget, use:

import datetime
self.my_lineedit_objectname.setValue(datetime.datetime.now())`

If you want to set it to QLabel widget. self.my_label_objectname.setText(datetime.datetime.now())

Replace my_lineedit_objectname and my_label_objectname with the actual object name in the UI file. You can assign any variable in place of datetime.datetime.now().

3
  • Did not help. I built my UI file with Qt Designer and then load it into QGIS. I don't see any Python code.
    – noclueGIS
    Commented Aug 1, 2021 at 4:40
  • Are you trying to create a python plugin or C++?
    – wondim
    Commented Aug 1, 2021 at 8:56
  • You need to add the code that shows how you are integrating the UI file into QGIS.
    – wondim
    Commented Aug 1, 2021 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.