Results 1 to 20 of 21

Thread: About setIndexWidget

Hybrid View

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

    Default About setIndexWidget

    Dear All

    I create a table view like
    Qt Code:
    1. q.exec("crate view .....");
    2.  
    3. model ->setTable("tum_hareket_fisleri");
    4. model ->select();
    5.  
    6. tableView->setModel(model );
    7. for (int i = 0; i < model ->rowCount(); ++i) {
    8. QCheckBox *cbox = new QCheckBox(tableView);
    9. tableView->setIndexWidget(model ->index(i, 16), cbox);
    10. }
    To copy to clipboard, switch view to plain text mode 

    But I am not able to get a check box in my table any idea?

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

    Default Re: About setIndexWidget

    any one? any idea?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: About setIndexWidget

    How many columns does your sql model have?
    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.


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

    Default Re: About setIndexWidget

    I got 15

    I try to

    Qt Code:
    1. tableView->insertColumn(16);
    To copy to clipboard, switch view to plain text mode 

    But notting changes

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: About setIndexWidget

    Quote Originally Posted by aekilic View Post
    I got 15
    So trying to insert something into the 17th column probably shouldn't have any effect, should it?

    I try to

    Qt Code:
    1. tableView->insertColumn(16);
    To copy to clipboard, switch view to plain text mode 

    But notting changes
    You can't add columns to sql models just like that.

    I think what you really want is to use Qt::CheckStateRole. That's only a teaser - how to use it is left as an exercise to you.
    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.


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

    Default Re: About setIndexWidget

    I did it with

    Qt::CheckStateRole

    But the problem is check box is not editable...

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: About setIndexWidget

    Because you didn't implement setData() and flags() for your model.
    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.


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

    Default Re: About setIndexWidget

    I do it like

    Qt Code:
    1. class MyModel : public QSqlQueryModel {
    2. Q_OBJECT
    3. public:
    4. MyModel(QObject *parent = 0);
    5. Qt::ItemFlags flags(const QModelIndex &index) const;
    6. QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
    7. ........
    8. };
    9.  
    10. Qt::ItemFlags MyModel::flags(const QModelIndex &index) const {
    11. Qt::ItemFlags flags = QSqlQueryModel::flags(index);
    12. if (index.column() == aColWithCheckbox)
    13. flags |= Qt::ItemIsUserCheckable;
    14. else
    15. flags |= Qt::ItemIsEditable;
    16. return flags;
    17. }
    18.  
    19. QVariant MyModel::data(const QModelIndex &index, int role) const {
    20. QVariant value = QSqlQueryModel::data(index, role);
    21. if (role == Qt::CheckStateRole && index.column() == aColWithCheckbox)
    22. return (QSqlQueryModel::data(index).toInt() != 0) ? Qt::Checked : Qt::Unchecked;
    23. else
    24. return value;
    25. }
    To copy to clipboard, switch view to plain text mode 

    But as I have told you I could not check the qcheckbox

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

    Default Re: About setIndexWidget

    do I missed anything?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: About setIndexWidget

    You didn't implement setData().
    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.


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

    Default Re: About setIndexWidget

    I have writen the setData didnt paste

    my code is exactly like this

    Qt Code:
    1. Qt::ItemFlags CustomModel::flags(const QModelIndex &index) const {
    2. Qt::ItemFlags flags = QSqlTableModel::flags(index);
    3. if (index.column() == 16)
    4. flags |= Qt::ItemIsUserCheckable | Qt::ItemIsEditable;
    5. return flags;
    6. }
    7.  
    8. QVariant CustomModel::data(const QModelIndex &index, int role) const
    9. {
    10. if (role == Qt::CheckStateRole && index.column() == 16)
    11. return (QSqlQueryModel::data(index).toInt() != 0) ? Qt::Checked : Qt::Unchecked;
    12.  
    13. return value;
    14. }
    15. bool CustomModel::setData(const QModelIndex &index, const QVariant &value, int role) {
    16. if(role==Qt::CheckStateRole)
    17. return QSqlTableModel::setData(index,value.toBool(),Qt::EditRole);
    18. return QSqlTableModel::setData(index,value);
    19. }
    To copy to clipboard, switch view to plain text mode 

    The check box on the table is still not editable, I can not check the qcheckbox...

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: About setIndexWidget

    One time you are using QSqlQueryModel as your base class and the other time you are using QSqlTableModel. So which one is it?
    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.


Similar Threads

  1. having problem with setIndexWidget
    By hamid ghous in forum Qt Programming
    Replies: 0
    Last Post: 10th November 2009, 05:01
  2. Model View - Delegate - setIndexWidget
    By starcontrol in forum Qt Programming
    Replies: 16
    Last Post: 2nd April 2008, 14:30
  3. setIndexWidget and proxy interaction
    By Derf in forum Qt Programming
    Replies: 3
    Last Post: 25th March 2006, 18:15

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
  •  
Qt is a trademark of The Qt Company.