Results 1 to 3 of 3

Thread: Delete if row checked

  1. #1
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Thanks
    20
    Thanked 5 Times in 5 Posts
    Qt products
    Platforms
    Unix/X11 Windows

    Question Delete if row checked

    I try created my own model for add checkbox in first column tableview.

    Qt Code:
    1. #ifndef MODELANGGOTA_H
    2. #define MODELANGGOTA_H
    3.  
    4. #include <QSqlQueryModel>
    5.  
    6. class modelAnggota : public QSqlQueryModel
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. modelAnggota(QObject *parent = 0);
    12. QVariant data(const QModelIndex &item, int role) const;
    13.  
    14. };
    15.  
    16. #endif // MODELANGGOTA_H
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. #include "modelanggota.h"
    2.  
    3. modelAnggota::modelAnggota(QObject *parent)
    4. : QSqlQueryModel(parent)
    5. {
    6.  
    7. }
    8.  
    9. QVariant modelAnggota::data(const QModelIndex &index, int role) const
    10. {
    11. if (role == Qt::CheckStateRole && index.column() == 0)
    12. return Qt::Unchecked;
    13.  
    14. return QSqlQueryModel::data(index, role);
    15. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QSqlQueryModel *model = new modelAnggota();
    2. model->setQuery("select * from mailbox");
    3.  
    4. ui->tableView->setModel( model );
    5. ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
    6. ui->tableView->setAlternatingRowColors(TRUE);
    7. ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
    8. ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    To copy to clipboard, switch view to plain text mode 

    But checkbox can't checked or unchecked. I need the checkbox not for edited data on table (database), but just for checked. Then, if I Click a pushButton (delete button), row with checked will remove. And yes, row in database table will removed too.


    Have any suggestion ?

    Sorry. my english is bad

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Delete if row checked

    You should look at the QAbstractItemModel::flags method and return Qt::ItemIsUserCheckable and possibly some other flags for the check box column.

  3. #3
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Thanks
    20
    Thanked 5 Times in 5 Posts
    Qt products
    Platforms
    Unix/X11 Windows

    Question Re: Delete if row checked

    You mean like this ? Ah, not work.

    Qt Code:
    1. Qt::ItemFlags modelAnggota::flags(const QModelIndex &index) const
    2. {
    3. if (index.column()==0)
    4. return Qt::ItemIsEditable|Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemIsUserCheckable;
    5.  
    6.  
    7. return QAbstractItemModel::flags(index);
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. new & delete usage.
    By SteveH in forum Newbie
    Replies: 2
    Last Post: 13th March 2009, 22:50
  2. Replies: 4
    Last Post: 19th February 2009, 11:10
  3. Best way for a graphicsitem to delete itself
    By pherthyl in forum Qt Programming
    Replies: 7
    Last Post: 22nd June 2008, 05:57
  4. Delete dialog
    By Krish_ng in forum Qt Programming
    Replies: 3
    Last Post: 9th August 2007, 12:42
  5. c++, placement delete upon exception
    By stinos in forum General Programming
    Replies: 6
    Last Post: 31st October 2006, 15:38

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.