Results 1 to 9 of 9

Thread: How to make a column read-only in QSqlRelationalTableModel?

  1. #1
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default How to make a column read-only in QSqlRelationalTableModel?

    Dear All

    We have a QSqlRelationalTableModel, and we would like to make a column read-only? Is there any example codes that could help us?

    Thanks!

    AEK

  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: How to make a column read-only in QSqlRelationalTableModel?

    Subclass the model and reimplement the flags() method to not return Qt::ItemIsEditable for items in the first column.

  3. #3
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to make a column read-only in QSqlRelationalTableModel?

    Could you please help us a little with a example! We are a bit new to QT

  4. #4
    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: How to make a column read-only in QSqlRelationalTableModel?

    Qt Code:
    1. class MyModel : public QSqlRelationalTableModel {
    2. public:
    3. MyModel(QObject *parent=0) : QSqlRelationalTableModel(parent){}
    4. Qt::ItemFlags flags ( const QModelIndex & index ) const{
    5. if(index.column()!=0)
    6. return QSqlRelationalTableModel::flags(index);
    7. return (QSqlRelationalTableModel::flags(index) & ~Qt::ItemIsEditable);
    8. }
    9. };
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to make a column read-only in QSqlRelationalTableModel?

    Quote Originally Posted by aekilic View Post
    Could you please help us a little with a example! We are a bit new to QT
    i attach a sample at end of class cpp you find the mysql structure....
    Attached Files Attached Files

  6. #6
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to make a column read-only in QSqlRelationalTableModel?

    Let me explain more in our .h we call relationaltable below,

    QSqlRelationalTableModel *model = new QSqlRelationalTableModel;
    model->setTable("stokdakiler");
    model->setFilter("stokid = " + Stokid);
    model->setEditStrategy(QSqlRelationalTableModel::OnField Change);
    model->setRelation(2, QSqlRelation("marka", "markaid", "marka"));
    model->setRelation(4, QSqlRelation("birimler", "birimid", "birim"));
    model->select();

    table->setModel(model);
    table->resizeColumnsToContents ();
    table->resizeRowsToContents ();
    table->setColumnHidden (0, true);
    table->setColumnHidden (1, true);
    table->setItemDelegate(new QSqlRelationalDelegate(tablestokda));
    table->setSortingEnabled (true);

    And after this what should we do?

  7. #7
    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: How to make a column read-only in QSqlRelationalTableModel?

    You should substitute all occurences to QSqlRelationalTableModel with "MyModel" (based on the code I have given you - if you change the class name, change it here as well).

  8. The following user says thank you to wysota for this useful post:

    aekilic (28th May 2007)

  9. #8
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to make a column read-only in QSqlRelationalTableModel?

    Quote Originally Posted by aekilic View Post
    Let me explain more in our .h we call relationaltable below,
    And after this what should we do?
    Build it..

    other crude sample....
    http://www.qtcentre.org/forum/f-qt-s...dmin-6807.html

  10. The following user says thank you to patrik08 for this useful post:

    aekilic (28th May 2007)

  11. #9
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to make a column read-only in QSqlRelationalTableModel?

    Thank you very much both of you, we were able to solve the problem easly!

Similar Threads

  1. QIODevice read()
    By ShaChris23 in forum Newbie
    Replies: 1
    Last Post: 3rd May 2007, 00:29
  2. Window OS make distclean && qmake && make one line
    By patrik08 in forum General Programming
    Replies: 4
    Last Post: 22nd March 2007, 10:43
  3. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 05:57
  4. Replies: 0
    Last Post: 10th November 2006, 13:46
  5. hidden QListView column suddenly visible
    By edb in forum Qt Programming
    Replies: 10
    Last Post: 27th January 2006, 08:00

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.