PDA

View Full Version : Reimplement currentChanged and selectionChanged problems ??



tonnot
20th April 2011, 08:24
I want to know when the user change the current cell, and when the selection change So I use currentChanged and selectionchanged reimplemented for my custom tableview.

Ok, I dont know what is the problem but If I do click on a cell I need to wait almost a second to view the current cell selected......
(And I have comment the possible code asociated to each slot)

Any Idea ?

agarny
20th April 2011, 09:44
Any Idea ?If you were to provide us with some code, it would probably help us to help you... Have you checked the original implementation of those methods to make sure that you are not missing something that is critical? Also, if you might not want to call QTableView::currentChanged, you might still want to call QAbstractItemView::currentChanged...?

tonnot
20th April 2011, 10:43
I only have this code (without any other commands inside them :

void A_table::currentChanged ( const QModelIndex & current, const QModelIndex & previous ) {}
void A_table::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected){}

And as public slots :

public slots:
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
void currentChanged ( const QModelIndex & current, const QModelIndex & previous );

A_table is a custom widget extending QTableView and it is connected to a custom model extending QAbstractTableModel(parent)
All works fine except this issue.
Thanks

agarny
20th April 2011, 10:50
I have never 'converted' a protected virtual function into a public slot, so I have no idea whether it can/should work, but what is certain is that you are not calling any of the parent's implementation of those methods and that might be the cause of your problem. Have you tried to put a trace in your version of those methods, just to make sure that they are actually being executed?

tonnot
20th April 2011, 11:05
But they are slots. So If I use a Qwidget extendig a QTableView I have to declare as public slots , ins't ?

And this are the only properties I set :


this->setSortingEnabled(false);
this->setSelectionBehavior(QAbstractItemView::SelectItem s);
this->setSelectionMode( QAbstractItemView::SingleSelection);
this->horizontalHeader()->setStretchLastSection(true);
this->setEditTriggers(QAbstractItemView::NoEditTriggers) ;

By now, I have to comment selectionchanged.
Another strange behavior is that every cell I click remains selected,.

Keep needing help on this.

agarny
20th April 2011, 11:12
Keep needing help on this.No, what you need is to do your homework and read Qt's documentation (more carefully, if you have already read it).

tonnot
20th April 2011, 11:26
From help : (model view tutorial)
Views manage selections within a separate selection model, which can be retrieved with the selectionModel() method. We retrieve the selection Model in order to connect a slot to its selectionChanged() signal.
So, I have now something likethis:

QItemSelectionModel *selectionModel= Table>selectionModel();
connect(selectionModel, SIGNAL(selectionChanged (const QItemSelection &, const QItemSelection &)),
this, SLOT(selectionChangedSlot(const QItemSelection &, const QItemSelection &)));

Ok, now it works (not very well but I have not the last problems)

And, I can to reimplement the currentChanged slot or is it forbidden ?

PS: I pray everyday in order QT people include more information into QT Reference