Results 1 to 2 of 2

Thread: QDataWidgetMapper and QComboBox troubles

  1. #1
    Join Date
    Feb 2011
    Location
    Bulgaria
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QDataWidgetMapper and QComboBox troubles

    Hi there!
    I've run in troubles, when I try to use QComboBox with QDataWidgetMapper.
    I have a SQL table like this one -
    Qt Code:
    1. create table `test` (
    2. `id` int not null auto_increment,
    3. `name` varchar(255) not null,
    4. `color` enum('black', 'cyan', 'magenta', 'yellow', 'mix') default 'black',
    5. `enabled` enum('yes','no') default 'no',
    6. primary key(`id`),
    7. key(`enabled`)
    8. ) Engine=InnoDB default charset=utf8 collate=utf8_unicode_ci;
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDataWidgetMapper and QComboBox troubles

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QDataWidgetMapper and QComboBox
    By buckadl in forum Qt Programming
    Replies: 0
    Last Post: 8th December 2010, 22:40
  2. QDataWidgetMapper and QComboBox
    By scarleton in forum Qt Programming
    Replies: 4
    Last Post: 7th November 2010, 15:28
  3. QDataWidgetMapper and QComboBox
    By mazurekwrc in forum Qt Programming
    Replies: 0
    Last Post: 31st March 2009, 14:02
  4. QDataWidgetMapper and QCombobox
    By miraks in forum Qt Programming
    Replies: 4
    Last Post: 6th December 2008, 18:53
  5. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2007, 00:29

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.