Results 1 to 3 of 3

Thread: Using QDataWidgetMapper with custom types

  1. #1
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Using QDataWidgetMapper with custom types

    Good day.

    I have the following problem:
    1.) I have created a custom datatype "myType", declared it and it works like a charm.
    It includes an integer and a QStringList.

    2.) I am using this type in my model - it is a QAbstractItemModel based tree model. When i am creating the model structure i create this type, insert it into a QVariant and attach the QVariant into a Node. No surprises here.

    3.) The model returns the QVariant including my type in the data() function. Also standard procedure.

    4.) In my view i am using QDataWidgetMapper to map widgets to the model.
    When i map my widgets there are no problems with the standard datatypes. But when i map my custom type to a widget, the widget does not get updated.

    I understand that i could return only the integer part of my type in my model's data() function, but i need access to the QStringList from my View.

    Is it possible to integrate a custom type into QVariant so the QDataWidgetMapper will automatically map the desired type variable to my widget? If yes, how?

    p.s. I have not included any source code because it would in my opinion clutter the question, and because my final question is quite simple. Thank you.

  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: Using QDataWidgetMapper with custom types

    It's likely you should set a custom delegate on the data widget mapper if you are using custom types and implement setModelData()/setEditorData().
    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. The following user says thank you to wysota for this useful post:

    Zanyinj (25th August 2011)

  4. #3
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using QDataWidgetMapper with custom types

    Thank you, that was exactly what I needed to do.

Similar Threads

  1. QItemEditorFactory and custom enum types.
    By hickscorp in forum Qt Programming
    Replies: 4
    Last Post: 7th August 2011, 17:08
  2. Q_PROPERTY and deeply nested custom types
    By Sammy D'Souza in forum Newbie
    Replies: 1
    Last Post: 15th May 2010, 12:26
  3. Working with QDBus and custom types
    By JuBe in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2009, 17:20
  4. QVariant::toString and custom data types
    By Vladimir in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2007, 16:36
  5. QVariant types support for custom properties
    By Dusdan in forum Qt Tools
    Replies: 9
    Last Post: 11th January 2006, 10:55

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.