PDA

View Full Version : QTableView selection problem



aiprober
9th August 2007, 09:42
Hi,

I am developing a program using QTableView. I am sort of lazy using QStandardItemModel
to create the default empty table. The data inputed to the model is dynamic.

itemmodel_=new QStandardItemModel(0,5);
itemmodel_->setHeaderData(0, Qt::Horizontal, tr("View"));
itemmodel_->setHeaderData(1, Qt::Horizontal, tr("Gene type"));
itemmodel_->setHeaderData(2, Qt::Horizontal, tr("Proportion (%)"));
itemmodel_->setHeaderData(3, Qt::Horizontal, tr("Time (msec)"));
itemmodel_->setHeaderData(4, Qt::Horizontal, tr("Density"));

QItemSelectionModel* selmodel = ODTableView->selectionModel();
ODTableView->setSelectionMode(QAbstractItemView::ExtendedSelect ion);
QObject::connect(selmodel, SIGNAL(selectionChanged(const QItemSelection &,
const QItemSelection &)),
this, SLOT(slectionHandle(const QItemSelection &,
const QItemSelection &)) );

In my application I want to select "rows" or "all" to generate a signal to update statistical
graph in another dialog. But now the selectionChanged signal is not released when the
mouse changes selection in the table view. Actually, I tried to connect the signal even after
the table items are added but still not work. additionally, the table view is set to visible only if data are loaded. Can anyone help? :confused:

marcel
9th August 2007, 21:42
What about the currentChanged signal?

aiprober
10th August 2007, 11:41
Hi,
Thanks for reply! I thought no one would help.
actually I tried currentChanged signal. it is not working either. currently, I had a solution
using an eventfiler on the table view. However, I just want to know how to solve this
problem.
/AI

marcel
10th August 2007, 12:29
But this is not normal...
Can you post a small program that reproduces this bug?

What about the QAbstractItemViere::clicked(const QModelIndex&) signal?
At least one should get emitted when you select something.

Regards

aiprober
10th August 2007, 14:01
Hi,
yeah, it is a bit weird for me as well. Probably something silly I did :o.
But I tried clicked() signal in QTableView it works. I will try some simple
program since the application is not simple to show.
/AI

jpn
12th August 2007, 14:52
Could it be a missing Q_OBJECT (http://doc.trolltech.com/4.3/qobject.html#Q_OBJECT) macro? Does QObject::connect() output any warning?

aiprober
14th August 2007, 22:49
Hi,

I test abit and find that the real problem is that selection handling crashes when getting
selectionChanged() signal:

void ODCheckerDlg::selectionHandle( const QItemSelection& sel,
const QItemSelection& unsel)
{
....

const QList<QModelIndex>& indlist=sel.indexes();

.....

}

this crash appears in windows with QT4.2.

/AI

jpn
14th August 2007, 23:19
Could you prepare a minimal compilable example reproducing the problem, please?

MarkoSan
8th June 2008, 00:46
But according to 4.4.0 docs, selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) is a SLOT, not a SIGNAL. This logic is not understandable by me. Why is slot, it should be signal?! And how do I know according to parameters of this slot, what is the index of selected item in table?!

jpn
9th June 2008, 08:56
But according to 4.4.0 docs, selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) is a SLOT, not a SIGNAL. This logic is not understandable by me. Why is slot, it should be signal?! And how do I know according to parameters of this slot, what is the index of selected item in table?!
I guess you're talking about QAbstractItemView::selectionChanged() which is provided for convenience. But actually there is QItemSelectionModel::selectionChanged() which is a signal.

MarkoSan
9th June 2008, 10:21
I guess you're talking about QAbstractItemView::selectionChanged() (http://doc.trolltech.com/latest/qabstractitemview.html#selectionChanged) which is provided for convenience. But actually there is QItemSelectionModel::selectionChanged() (http://doc.trolltech.com/latest/qitemselectionmodel.html#selectionChanged) which is a signal.

So, in object, subclassed from QTableView, which one is now called?!

jpn
9th June 2008, 11:51
So, in object, subclassed from QTableView, which one is now called?!
The documentation is quite clear about that.

QItemSelectionModel::selectionChanged():

This signal is emitted whenever the selection changes.
QAbstractItemView::selectionChanged():

This slot is called when the selection is changed.
QAbstractItemView establishes the signal slot connection between the two.

MarkoSan
9th June 2008, 12:55
The documentation is quite clear about that.

QItemSelectionModel::selectionChanged() (http://doc.trolltech.com/latest/qitemselectionmodel.html#selectionChanged):

QAbstractItemView::selectionChanged() (http://doc.trolltech.com/latest/qabstractitemview.html#selectionChanged):

QAbstractItemView establishes the signal slot connection between the two.

Ok, but, actually, documentation IS NOT QUITE CLEAR ABOUT THAT. That is my point. :D

So, if that is the way, I have a problem: I have a subclassed QWidget and in it there is a subclassed QTableView and QPushButton. This QPushButton is initialy disabled (because QTableView is empty at runtime). The purpose of this QPushButton is to remove item from QTableView (when pressed), so if QTableView is NOT empty and NONE of items is selected, it must be disabled. So, I need to catch signal on selection change and enable this button. The problem is, that QTableView and QPushButton are not aware of each other and I must do it through parent QWidget. So, should I catch signal selectionChanged or SLOT selectionChanged?!