Results 1 to 5 of 5

Thread: Mapping.. ComboCheckBox using QDataWidgetMapper to SQLite

  1. #1
    Join Date
    Sep 2016
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Mapping.. ComboCheckBox using QDataWidgetMapper to SQLite

    Application created in Qt Creator uses combo check boxes. ComboCheckBox has uncheckable title item and checkable items:

    -- Choose position

    [ ] option1

    [ ] option2

    ...

    It is constructed by the following approach:

    Qt Code:
    1. // Model construction.
    2. QStandardItem* title = new QStandardItem(injuries.at(0));
    3. model.insertRow(0, title);
    4.  
    5. for (int i = 1; i < injuries.length(); i++)
    6. {
    7. QStandardItem* item = new QStandardItem(injuries.at(i));
    8.  
    9. item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
    10. item->setData(Qt::Unchecked, Qt::CheckStateRole);
    11.  
    12. model.insertRow(i, item);
    13. }
    14.  
    15. // Setting model for combo chech box.
    16. comboCheckBox->setModel(&model);
    To copy to clipboard, switch view to plain text mode 
    I'm trying to map data from SQLite to this combo check box by this way:

    Qt Code:
    1. mapper = new QDataWidgetMapper(this);
    2. mapper->setModel(model);
    3. mapper->setItemDelegate(new QSqlRelationalDelegate(this));
    4. mapper->addMapping(comboCheckBox, model->fieldIndex("inj1"), "currentIndex");
    To copy to clipboard, switch view to plain text mode 

    But to no avail. The same mapper works fine with usual check boxes:

    Qt Code:
    1. mapper->addMapping(checkBox, model->fieldIndex("inj1"), "currentIndex");
    To copy to clipboard, switch view to plain text mode 

    Is any way to map checkable flags from so kind of combo check box to the row of smth of the SQLite data base?

    I have failed to map even the current index not to mention separate checkable fields. Your elegant solutions would be just by the way for not very fancy combo check box.

  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: Mapping.. ComboCheckBox using QDataWidgetMapper to SQLite

    You need a custom delegate that will convert model data to editor data (QAbstractItemDelegate::setEditorData) according to your needs. Of course you'll also need a mapping the other way round (QAbstractItemDelegate::setModelData).
    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.


  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Mapping.. ComboCheckBox using QDataWidgetMapper to SQLite

    What is a combo check box?

    Cheers,
    _

  4. #4
    Join Date
    Sep 2016
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Mapping.. ComboCheckBox using QDataWidgetMapper to SQLite

    Thank you, wysota.

    But why do the following delegate doesn't work just for changing index:
    Qt Code:
    1. mapper = new QDataWidgetMapper(this);
    2. mapper->setModel(model);
    3. mapper->setItemDelegate(new QSqlRelationalDelegate(this));
    4. mapper->addMapping(comboCheckBox, model->fieldIndex("inj1"), "currentIndex");
    To copy to clipboard, switch view to plain text mode 
    What is the use of manual delegate?
    My editor (a la combo check box has the model already). To which another model I should delegate it?

    Quote Originally Posted by anda_skoa View Post
    What is a combo check box?
    It is a combo box with checkable items expect the title (first item).

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Mapping.. ComboCheckBox using QDataWidgetMapper to SQLite

    Quote Originally Posted by stanislavf View Post
    It is a combo box with checkable items expect the title (first item).
    Since that appears to be a custom class, does it have a writable "currentIndex" property?

    Cheers,
    _

Similar Threads

  1. Replies: 7
    Last Post: 19th October 2016, 19:48
  2. Replies: 8
    Last Post: 9th March 2014, 13:55
  3. tile mapping in qt?
    By even821 in forum Qt Programming
    Replies: 5
    Last Post: 16th November 2012, 14:14
  4. QSortFilterProxyModel mapping
    By Sparhawk in forum Qt Programming
    Replies: 1
    Last Post: 17th December 2011, 20:00
  5. Mapping between two comboboxes
    By codeman in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2009, 17:32

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.