I use Qt designer, create a new form, add several line edit (qLineEdit) widgets, rename them the same as the fields in a QGIS attribute table, and save. In QGIS I associate the new .ui file in Layer Properties -> Fields, Under the Attribute editor layout dropdown I select, "Provide ui-file" and point to the file just created. Everything works fine, the .ui form displays correctly when a feature is selected.

I need better control over number formatting in the Qt .ui form display. For example:

  1. One field is a double, Real length 18, precision 11 that I need rounded to two decimals with a decimal point.
  2. Other fields are qlonglong, Integer64, length 10, precision 0 that I need displayed with commas (only if needed) as 1000 separators.
  3. One field I'd like to divide by 1000, round to the nearest integer and display with a "k" trailing in the output. (O.K. that may be pressing it...)

Are these "Number formatting operations" done only by adding new columns to the attribute table and then sending the data over to Qt in the exact desired format or does Qt have the capability of formatting numbers, prior to display?

Sorry, no C or C++ background but plenty of Excel & VBA. Strikes me that Qt is somewhat like a form generator/report writer (and if so it should have all the formatting capability you would need? Documentation on Qt designer is pretty harsh on the "uninitiated".

With a report writer you would never tamper with the underlying database structure. So, it seems pretty non intuitive creating new columns... However if that's the best way to do it (using the expression builder functions) I can go that route and get the job done.

Ideas? qLineEdit inputMask may be a way to go but it seems to force the output of commas even when the number is small.

  • Do I use a "Python Init function" to write code to format the numbers ahead of when the QT form pops up? I see under Layer Properties -> Fields there is a facility to put some code behind (before) a form. The help "? "is non operational and the help button seems to bring up irrelevant information. I go to the Python init code window and note it pops up key words but other than that I can't see where you can name and save the .py file? Simple examples would be helpful, especially when transitioning from Windows "controls" over to QT "widgets" wiring. – rjlabs Jul 19 '16 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.