Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: About setIndexWidget

  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,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: 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,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: 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,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: 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,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: 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,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: 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.


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

    Default Re: About setIndexWidget

    Sorry

    QSqlTableModel it should be, working right now sorry for the delay and time, but right now I had a problem I could not check more than 2 rows?

  14. #14
    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: About setIndexWidget

    Did you solve the previous problem? What was 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.


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

    Default Re: About setIndexWidget

    I was not able to check the check box, but I could do it right now, but I could not check more than 2 check box, When I press the 3rd check box, the 1st check is removed.

  16. #16
    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: About setIndexWidget

    Please show us the current code.
    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.


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

    Default

    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. QVariant value = QSqlTableModel::data(index, role);
    11. if (index.column() == 16) {
    12. if (role == Qt::CheckStateRole)
    13. return (QSqlTableModel::data(index).toInt() != 0) ? Qt::Checked : Qt::Unchecked;
    14. }
    15. return value;
    16. }
    17. bool CustomModel::setData(const QModelIndex &index, const QVariant &value, int role) {
    18. if(role==Qt::CheckStateRole)
    19. return QSqlTableModel::setData(index,value.toBool(),Qt::EditRole);
    20. return QSqlTableModel::setData(index,value,Qt::EditRole);
    21. }
    To copy to clipboard, switch view to plain text mode 

    any thing you could suggest
    Last edited by aekilic; 15th December 2009 at 12:29.

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

    Default Re: About setIndexWidget

    is this possible, when I try to click for the 3rd check box, can the model be requested again? Because that is the only reason I could think.

    if it is like that, the only think I would like to do is check of the the rows on the table and send a signal take the id of the checked rows, but in this case I could not check more than 2 items

  19. #19
    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: About setIndexWidget

    Do you want to save the changes you make using checkboxes to the SQL database?
    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.


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

    Default Re: About setIndexWidget

    no I dont want to

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.