Results 1 to 4 of 4

Thread: QDataWidgetMapper and custom widget - read value

  1. #1
    Join Date
    Oct 2010
    Location
    Poland
    Posts
    26
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QDataWidgetMapper and custom widget - read value

    I’ve made a my widget which has a Q_PROPERTY like this:

    Qt Code:
    1. Q_PROPERTY(QDate date READ date WRITE setDate NOTIFY dateChanged USER true )
    To copy to clipboard, switch view to plain text mode 

    I created a QDataWidgetMapper and addMapping. The date from my widget is not readed by mapper. Even there is not invoked a date() method. What could be wrong? My class inherits from QFrame and has a Q_OBJECT macro.

  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 custom widget - read value

    Your code looks ok. You can try using a custom delegate with reimplemented setModelData() and 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. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QDataWidgetMapper and custom widget - read value

    I created a QDataWidgetMapper and addMapping. The date from my widget is not readed by mapper. Even there is not invoked a date() method. What could be wrong? My class inherits from QFrame and has a Q_OBJECT macro.
    What model is the mapper using? I guess the mapped section of the model does not return the QDate (in the QVariant).
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  4. #4
    Join Date
    Oct 2010
    Location
    Poland
    Posts
    26
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDataWidgetMapper and custom widget - read value

    I use QSqlTableModel.
    My widget has QCheckBox and QDateEdit. I use delegate to format date for SQLite.

    I made tests and I added my delegate. I have two situations:

    1. Without mapper->setSubmitPolicy (default is QDataWidgetMapper::AutoSubmit).
    setModelData from delegate is invoked for Qt widgets(QDateEdit too) but not when I set value in my widget.

    2. With mapper->setSubmitPolicy( QDataWidgetMapper::ManualSubmit ).
    submit() is called whed dialog is accepted. In this case setModelData operates on Qt widgets and take value from my widget too.

    Is this a bug or maybe I'm doing something wrong?

Similar Threads

  1. Replies: 16
    Last Post: 12th March 2020, 05:03
  2. Replies: 0
    Last Post: 19th March 2012, 20:09
  3. Using QDataWidgetMapper with custom types
    By Zanyinj in forum Qt Programming
    Replies: 2
    Last Post: 25th August 2011, 10:42
  4. Custom QLineEdit to store NULL with QDataWidgetMapper
    By certqt in forum Qt Programming
    Replies: 3
    Last Post: 9th November 2010, 14:15
  5. Replies: 2
    Last Post: 18th October 2010, 15:33

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.