Sorry for the delay. Weekend... 

Originally Posted by
aamer4yu
what state is NOW ? i mean did u change anything in the code ?
I've found a workaround. Now is finally working, but with some hacking. I've been looking inside QTreeView's "keyboardSearch" method. It moves current view's index when necessary, but it also moves to the first column. I don't know why...
Perhaps an example would be clearer. Image a "simple" tree structure like this ( it's shown on screen as a plain table ) :
ROOT
|---- Child 0 ( 5 columns )
|---- Child 1 ( 5 columns )
|---- Child 2 ( 5 columns )
...
If you are selecting third column, and you move up / down with arrows, you may stay on third column. I cannot find the reason because trolls decided to switch on every row change to column 0. So I made this hack :
void keyboardSearch
( const QString & search
) {
int iCol = currentIndex().column();
setCurrentIndex ( model()->sibling ( currentIndex().row(), iCol, currentIndex() ) );
}
void keyboardSearch ( const QString & search )
{
int iCol = currentIndex().column();
QTreeView::keyboardSearch ( search );
setCurrentIndex ( model()->sibling ( currentIndex().row(), iCol, currentIndex() ) );
}
To copy to clipboard, switch view to plain text mode
Also, I'm doing some minor changes to even method, to catch Left/Right, PgUp/PgDown, Home/End keys and allow user to move in a logical way.
void SelectCell ( int Key )
{
int iCol = 0;
switch ( Key )
{
case Qt::Key_Right : iCol = 1; break;
case Qt::Key_Left : iCol = -1; break;
}
iCol = qMax ( 0, qMin ( AUX.column() + iCol, model()->columnCount() - 1 ) );
setCurrentIndex ( model()->sibling ( AUX.row(), iCol, currentIndex() ) );
};
{
if ( qe
->type
() != QEvent::KeyPress )
QKeyEvent * ke
= dynamic_cast<QKeyEvent
*>
(qe
);
switch ( ke->key() )
{
case Qt::Key_Right :
case Qt::Key_Left :
{
SelectCell ( ke->key() );
qe->accept();
return true;
}
case Qt::Key_Up :
case Qt::Key_Down :
case Qt::Key_PageUp :
case Qt::Key_PageDown :
case Qt::Key_Home :
case Qt::Key_End :
{
int iCol = currentIndex().column();
if ( inherited::event ( qe ) )
{
setCurrentIndex ( model()->sibling ( currentIndex().row(), iCol, currentIndex() ) );
return true;
}
return false;
}
break;
<other stuff ...>
}
}
void SelectCell ( int Key )
{
int iCol = 0;
switch ( Key )
{
case Qt::Key_Right : iCol = 1; break;
case Qt::Key_Left : iCol = -1; break;
}
QModelIndex AUX = currentIndex ();
iCol = qMax ( 0, qMin ( AUX.column() + iCol, model()->columnCount() - 1 ) );
setCurrentIndex ( model()->sibling ( AUX.row(), iCol, currentIndex() ) );
};
bool event ( QEvent * qe )
{
if ( qe->type() != QEvent::KeyPress )
return QTreeView::event ( qe );
QKeyEvent * ke = dynamic_cast<QKeyEvent *>(qe);
switch ( ke->key() )
{
case Qt::Key_Right :
case Qt::Key_Left :
{
SelectCell ( ke->key() );
qe->accept();
return true;
}
case Qt::Key_Up :
case Qt::Key_Down :
case Qt::Key_PageUp :
case Qt::Key_PageDown :
case Qt::Key_Home :
case Qt::Key_End :
{
int iCol = currentIndex().column();
if ( inherited::event ( qe ) )
{
setCurrentIndex ( model()->sibling ( currentIndex().row(), iCol, currentIndex() ) );
return true;
}
return false;
}
break;
<other stuff ...>
return QTreeView::event ( qe );
}
}
To copy to clipboard, switch view to plain text mode
I wonder about Qt's default behavior
. I cannot find the reason because they consider better to "jump" to the first column every time you change the row of the index.
They must, at least, consider this option. In many cases ( a great % of times ) when you show a tree with multiple columns, the data has the same number of columns in all the rows.
also what is the speed of typing ? usually the moment you delay typing, the text entered till that time is searched.
It's not an speed problem, I've done this on my program startup :
QApplication::setKeyboardInputInterval ( 1000 );
So 1 second between keystrokes is sufficient enough for my users...
Bookmarks