Results 1 to 2 of 2

Thread: Does QDataWidgetMapper use flags?

  1. #1
    Join Date
    May 2008
    Location
    New Zealand
    Posts
    2
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Does QDataWidgetMapper use flags?

    I have derived my own model from QAbstractTableModel, including implementing Qt::ItemFlags flags ( const QModelIndex & index ).

    When I display the model using QTableView, it responds as expected to the flags that I set for a given column:
    eg. Qt::ItemIsEnabled allows mouse interaction with the column
    Qt::ItemIsEditable allows the cell to be edited

    When I connect the model to a QDataWidgetMapper, I expected the flags to similarly interact with the widgets in the mapper. eg. I would expect that the widget would be disabled if Qt::ItemIsEnabled is not set. In my testing that doesn't seem to happen.

    Am I missing something here?

    Or does QDataWidgetMapper completely ignore the model flags?

    Example given below is a very basic model, in which flags() returns Qt::ItemIsSelectable only. In my thinking this should disable the mapped widget and not permit editing. In fact it is enabled and editable.

    Any help here would be very much appreciated. Thanks in advance.

    Qt Code:
    1. class myModel : public QAbstractTableModel
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. myModel();
    7. int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
    8. int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
    9. QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
    10. bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
    11. QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
    12. Qt::ItemFlags flags ( const QModelIndex & index ) const;
    13. protected:
    14. QList<QString> c1;
    15. QList<QString> c2;
    16. };
    17.  
    18. int myModel::rowCount ( const QModelIndex & parent ) const
    19. {
    20. return c1.count();
    21. }
    22.  
    23.  
    24.  
    25. int myModel::columnCount ( const QModelIndex & parent ) const
    26. {
    27. return 2;
    28. }
    29.  
    30.  
    31.  
    32. QVariant myModel::data ( const QModelIndex & index, int role ) const
    33. {
    34. if ( (role != Qt::DisplayRole) && (role != Qt::EditRole) )
    35. return QVariant();
    36. return (index.column() == 0) ? QVariant(c1.at(index.row())) : QVariant(c2.at(index.row()));
    37. }
    38.  
    39.  
    40.  
    41. bool myModel::setData ( const QModelIndex & index, const QVariant & value, int role )
    42. {
    43. if (index.column() == 0)
    44. c1[index.row()]= value.toString();
    45. else
    46. c2[index.row()]= value.toString();
    47. emit dataChanged( this->index(0,0), this->index(c1.count(),1));
    48. return true;
    49. }
    50.  
    51. QVariant myModel::headerData ( int section, Qt::Orientation orientation, int role ) const
    52. {
    53. return QVariant(QString(""));
    54. }
    55.  
    56. Qt::ItemFlags myModel::flags( const QModelIndex & index ) const
    57. {
    58. return Qt::ItemIsSelectable;
    59. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Dec 2016
    Location
    New England, US
    Posts
    31
    Thanks
    6
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Does QDataWidgetMapper use flags?

    Quote Originally Posted by Netwiz View Post

    Or does QDataWidgetMapper completely ignore the model flags?
    Wow, no one has responded in 12 years! The answer is NO. Qt ignores item flags - I have looked into QDataWidgetMapper code (for a completely different reason).

    Why did I stumble upon this after 12 years? I was looking for an answer to this question: a widget which has some data, became disabled/invisible due to some choice in GUI, does it continue to participate in mapping to model? For example: let's say the choices are rectangle or triangle for a 2D figure, having 4 and 3 pairs of coordinates respectively through QLineEdit. And someone converted a rectangle to a triangle: I can easily disable/hide the last row. But the widget is still there - does the data get transferred, say under, manual submit mode? If the data transferred is empty QVariant(), that's fine. But I believe that's not the case.

Similar Threads

  1. QDataWidgetmapper
    By locus in forum Qt Programming
    Replies: 7
    Last Post: 5th June 2012, 12:24
  2. QDataWidgetMapper with QGroupBox
    By Nightfox in forum Qt Programming
    Replies: 2
    Last Post: 22nd October 2009, 17:17
  3. QDataWidgetMapper with QTreeView
    By Nightfox in forum Qt Programming
    Replies: 2
    Last Post: 1st September 2009, 20:58
  4. QDataWidgetMapper
    By rogerholmes in forum Newbie
    Replies: 4
    Last Post: 24th March 2009, 20:32
  5. QSplashScreen Weirdness
    By mclark in forum Qt Programming
    Replies: 11
    Last Post: 19th November 2007, 07:49

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.