Results 1 to 6 of 6

Thread: QListView removing rows problems

  1. #1
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy QListView removing rows problems

    Hi,

    Sorry if this question already was debated but I'm with a big proble here:

    I populate a QListView in this way:

    QStandardItemModel *model = new QStandardItemModel;
    int row=0;
    for(int i=0; i<= files.size()-1;++i) {
    if(files.at(i).isEmpty() )
    break;
    QStandardItem *item = new QStandardItem;
    item->setText(files.at(i));
    item->setIcon(QPixmap::fromImage(images->resultAt(i)));
    item->setTextAlignment(Qt::AlignLeft);
    item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
    model->setItem(row, 0, item);
    ++row;
    }
    LV_IMAGES->setModel(model);
    LV_IMAGES->show();

    At this point all ok. Now I want remove a row from QListView LV_IMAGES them I use:

    int r = LV_IMAGES->currentIndex().row();
    //mdlThumbs->takeRow(r);
    if( mdlThumbs->removeRows(r, 1,LV_IMAGES->currentIndex()) )
    qDebug() << "OK";
    else
    qDebug() << "NO";


    But nothing is happening and always returns "NO"
    Were is the error?

    Thanks in advance

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QListView removing rows problems

    in short: currentIndex() is the index you want to remove, NOT the parent and especially not both:

    Qt Code:
    1. QModelIndex cur = LV_IMAGES->currentIndex();
    2. if( cur.isValid() && mdlThumbs->removeRow(cur.row(), cur.parent()) )
    3. qDebug() << "OK";
    4. else
    5. qDebug() << "NO";
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListView removing rows problems

    Hi (again),

    See the result of your code suggested:

    cur.isValid() ==> TRUE
    mdlThumbs->removeRow(cur.row(), cur.parent()) ==> FALSE

    Them the row not was removed from list.
    The items still stayed visibles in the list.

    Some new suggestions?

    Thanks.

  4. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QListView removing rows problems

    and whats the mdlThums? Where and how do you get it?

    P.S. Use CODE tags for pasting code. (the '#' button)
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  5. #5
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListView removing rows problems

    Hi,

    mdlThumbs is the QStandardItemModel pointer.

    Qt Code:
    1. QStandardItemModel *mdlThumbs;
    To copy to clipboard, switch view to plain text mode 
    The pointer above is definided inside class definition and a new instace is created in the constructor

    Qt Code:
    1. DocFiscais::DocFiscais(QWidget* parent, Qt::WFlags fl)
    2. : QWidget( parent, fl ), Ui::frmDFiscal()
    3. {
    4. setupUi(this);
    5.  
    6. mdlThumbs = new QStandardItemModel;
    7.  
    8. (....)
    9. }
    To copy to clipboard, switch view to plain text mode 

    That this.

    Thanks

  6. #6
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListView removing rows problems

    Hi faldżip,

    Your question did me see where this the problem.
    I was using the "model" but should use the mdlThumbs in code.
    I wasn't seeing this.

    I would like to thank to everybody that help me to see better where was the problem.

    Thanks a Lot, and sorry for any inconvenient.

Similar Threads

  1. Removing all items QListView
    By vcp in forum Qt Programming
    Replies: 2
    Last Post: 6th August 2009, 18:55
  2. removing of selected rows
    By MrShahi in forum Qt Programming
    Replies: 4
    Last Post: 10th June 2008, 15:05
  3. Problems customizing tooltips in QListView
    By kalos80 in forum Qt Programming
    Replies: 6
    Last Post: 14th November 2007, 22:46
  4. Removing rows
    By indifference in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2007, 16:54

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.