PDA

View Full Version : QDataWidgetMapper and QComboBox troubles



thec0der
2nd February 2011, 09:56
Hi there!
I've run in troubles, when I try to use QComboBox with QDataWidgetMapper.
I have a SQL table like this one -


create table `test` (
`id` int not null auto_increment,
`name` varchar(255) not null,
`color` enum('black', 'cyan', 'magenta', 'yellow', 'mix') default 'black',
`enabled` enum('yes','no') default 'no',
primary key(`id`),
key(`enabled`)
) Engine=InnoDB default charset=utf8 collate=utf8_unicode_ci;


I'd expected, when I map QComboBox with table index for field "color" or "enabled", to have a list of all enum values loaded in QComboBox, and when I iterate trough records, selected value in QComboBox to be the value from current record.
Unfortunately nor the QComboBox was filled with enum values, nor select value from current record.
Any ideas?

Thanks,
D. Michev

wysota
2nd February 2011, 09:59
Implement a custom delegate and reimplement setModelData() and setEditorData() so that it performs the conversion between the model and the editor. Then set your custom delegate on the widget mapper. I don't know if QSqlTableModel reads your enums properly, I doubt so, so you might also have to subclass the model and "fix" it according to your use-case.