June 8, 2011

VincentD VincentD
Lab Rat
2 posts

[Solved] QT designer 2.2.0 - SQL request in a Combo Box

 

Hello,
I would like to create a user interface in QGIS (geographical information system software, developped in QT) with QT designer.
I can only join an “.ui “ file to my QGIS project.
I thus created an interface with QT designer, who works (almost) perfectly.
My only problem comes from the ComboBox.
Is there a way to include a list which arises of a SQL request, or a text file?
(My list to be included contains several hundreds of items, I cannot enter them manually).
Thanks for help!

Vincent

3 replies

June 8, 2011

loladiro loladiro
Lab Rat
596 posts

I have never used QGIS, but here’s what I think.
As long as you list is static you can do the following:
All .ui files are basically just XML files and a QComboBox is represented by the following XML elelemt:

  1.          <widget class="QComboBox" name="name">
  2.           <item>
  3.            < property name="text">
  4.             <string>Test</string>
  5.            </property>
  6.           </item>
  7.          </widget>

As you can see an item is represented by a “<item>” tag. You could write a little tool that parses the text file and manipulates the .ui file accordingly. Does that help?

P.S. the space between “<” and “property” is just to have it show up and not interpreted as an HTML tag (at least I think that’s why i wouldn’t show up otherwise)

June 9, 2011

VincentD VincentD
Lab Rat
2 posts

Hello loladiro,

Yes, it works!!!!!!!

I’ve exported my PostGIS table in CSV format.
With search/replace functions in Notepad++, I ‘ve added the tags around each item, and pasted the result in the .ui file.
Now my ComboBox shows items from my PostGIS table.

Thank you very much!
Regards,
Vincent

June 9, 2011

loladiro loladiro
Lab Rat
596 posts

Always glad to help. And don’t forget to add [Solved] in front of the title (by editing the first post).

 
  ‹‹ Qt Creator Git Tricks      Fail to create sub menu entries under Mainwindow ››

You must log in to post a reply. Not a member yet? Register here!