PDA

View Full Version : data-aware widgets



thePanz
16th December 2008, 18:38
Hi, I'm really a newbe in QT world! I'm creating a software that manage data from a DB and presents it to the user. I'm using some Model/View Widgets but I'd like to connect them with a "datasource"... I mean: I have a comboBox that display a item name, and I like to populate some text-fields with item-details.
as an expample I have a table with (ID, name, description, price), in my comboBox I need to display only "name" column, and when user chooses another "name" I need to populate some (read-only) text-fields with description and price. Is there any widget that do that "automatically"?

Regards!

jpn
16th December 2008, 20:05
You can use an SQL model with QComboBox, and QDataWidgetMapper might be handy whilst mapping widgets to certain fields.

thePanz
17th December 2008, 14:34
Thank you so much! For completeness I report a code (found in QT docs) to do what I mean (for future reference)


QDataWidgetMapper *mapper = new QDataWidgetMapper;
mapper->setModel(model);
mapper->addMapping(mySpinBox, 0);
mapper->addMapping(myLineEdit, 1);
mapper->addMapping(myCountryChooser, 2);
mapper->toFirst();

Thank you again! :)