PDA

View Full Version : QListView removing rows problems



vcp
15th September 2009, 15:47
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

caduel
15th September 2009, 17:12
in short: currentIndex() is the index you want to remove, NOT the parent and especially not both:



QModelIndex cur = LV_IMAGES->currentIndex();
if( cur.isValid() && mdlThumbs->removeRow(cur.row(), cur.parent()) )
qDebug() << "OK";
else
qDebug() << "NO";

vcp
15th September 2009, 18:18
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.

faldzip
15th September 2009, 18:51
and whats the mdlThums? Where and how do you get it?

P.S. Use CODE tags for pasting code. (the '#' button)

vcp
15th September 2009, 19:02
Hi,

mdlThumbs is the QStandardItemModel pointer.



QStandardItemModel *mdlThumbs;

The pointer above is definided inside class definition and a new instace is created in the constructor



DocFiscais::DocFiscais(QWidget* parent, Qt::WFlags fl)
: QWidget( parent, fl ), Ui::frmDFiscal()
{
setupUi(this);

mdlThumbs = new QStandardItemModel;

(....)
}


That this.

Thanks

vcp
15th September 2009, 19:22
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.