Results 1 to 5 of 5

Thread: connecting qcombobox with qdatawidgetmapper

  1. #1
    Join Date
    Jan 2017
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default connecting qcombobox with qdatawidgetmapper

    I'm building an python MVC application with a qAbstractDataModel. I'm using a qDataWidgetMapper to populate fields in edit panel. That all works well and now I'm trying understand how to connect qcombobox to present options to the user.

    I expect that this is a very common use-case but I can't find any introductory examples of how to set it up. I've searched extensively on Google and Stackoverflow and I find things that make me think I need to build a custom qItemDelegate but I can't find a tutorial or example to get started.

    I'm sorry if I don't even know enough to ask the right question but please point me in the right direction.

    FWIW, my code is intended for an open source project but I've built a stand-alone version of the tool here: https://github.com/sliptonic/toollibrarytests

  2. #2
    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: connecting qcombobox with qdatawidgetmapper

    It depends on what your model has as the data for the cell which is represented by the combobox.

    If the data for this cell is an zero-based integer, then you can most likely map that directly into the combobox' currentIndex.

    Lets assume you have three values: "A", "B", "C", and the model associates the numbers 0, 1 and 2 respectively.

    Qt Code:
    1. QComboBox *combo = new QComboBox;
    2. combo->addItem("A");
    3. combo->addItem("B");
    4. combo->addItem("C");
    5.  
    6. dataWidgetMapper->addMapping(combo, columnInTheModel, "currentIndex");
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Jan 2017
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: connecting qcombobox with qdatawidgetmapper

    Thanks for the reply. Unfortunately my data isn't normalized like that. The model is storing the actual string.
    That's why I started looking at delegates.

    I have a function that converts from strings to indices and back.

  4. #4
    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: connecting qcombobox with qdatawidgetmapper

    Ah, I see.

    If the strings are predefined, then you could map to the combobox "currentText" property.

    If the strings change during runtime, then you'll indeed likely need a delegate.

    Cheers,
    _

  5. #5
    Join Date
    Jan 2017
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: connecting qcombobox with qdatawidgetmapper

    I've tried mapping to currentText but can't get it to work.

    Regardless, for translation and future proof, I'd prefer to load the choices at run time so I need the delegate. Which brings me back to my first post that I'm having trouble finding any Python examples of doing that.

Similar Threads

  1. QDataWidgetMapper and QComboBox
    By buckadl in forum Qt Programming
    Replies: 0
    Last Post: 8th December 2010, 21:40
  2. QDataWidgetMapper and QComboBox
    By scarleton in forum Qt Programming
    Replies: 4
    Last Post: 7th November 2010, 14:28
  3. QItemDelegate, QDataWidgetMapper and QComboBox
    By cydside in forum Qt Programming
    Replies: 7
    Last Post: 8th April 2009, 18:44
  4. QDataWidgetMapper and QComboBox
    By mazurekwrc in forum Qt Programming
    Replies: 0
    Last Post: 31st March 2009, 13:02
  5. QDataWidgetMapper and QCombobox
    By miraks in forum Qt Programming
    Replies: 4
    Last Post: 6th December 2008, 17:53

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.