Qt-interest Archive, December 2006
Re: QTableView + QSqlQueryModel
Message 1 in thread
Yong schrieb:
> So by having a click in view we have to have a valid "currentIndex()".
> At this point if I press
> "|<< Go To Previous" there is nothing happening.
>
> void CLassName::slot_previous()
> {
> QModelIndex modelIndex = _tableView->currentIndex();
>
> int row = modelIndex.row() - 1;
> int column = modelIndex.column();
>
> QModelIndex newCurrentIndex = modelIndex.sibling(row,column);
>
> _tableView->setCurrentIndex( newCurrentIndex );
> //_tableView->selectionModel()->select( newCurrentIndex,
> QItemSelectionModel::Select );
> _tableView->selectRow( row );
> }
I don't know; the code seems OK for me. You'll have to debug the method
yourself. Are modelIndex and newCurrentIndex valid indices (indicated by
-1 in their row and column properties)? Which values do row and column
have? Have you checked the selection mode and behavior of your view?
Martin
--
[ signature omitted ]
Message 2 in thread
Found the cause of the problem.
For those who is interested, usually it is good style to do the following
;)
connect( buttonGoPrevious, SIGNAL(clicked(bool)), this,
SLOT(slot_previous()) );
On Fri, 01 Dec 2006 08:12:26 -0000, Martin Gebert
<Martin.Gebert@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> Yong schrieb:
>> So by having a click in view we have to have a valid "currentIndex()".
>> At this point if I press
>> "|<< Go To Previous" there is nothing happening.
>> void CLassName::slot_previous()
>> {
>> QModelIndex modelIndex = _tableView->currentIndex();
>> int row = modelIndex.row() - 1;
>> int column = modelIndex.column();
>> QModelIndex newCurrentIndex = modelIndex.sibling(row,column);
>> _tableView->setCurrentIndex( newCurrentIndex );
>> //_tableView->selectionModel()->select( newCurrentIndex,
>> QItemSelectionModel::Select );
>> _tableView->selectRow( row );
>> }
>
> I don't know; the code seems OK for me. You'll have to debug the method
> yourself. Are modelIndex and newCurrentIndex valid indices (indicated by
> -1 in their row and column properties)? Which values do row and column
> have? Have you checked the selection mode and behavior of your view?
>
> Martin
>
--
[ signature omitted ]