Search tool not get the alpha numeric key events from watched widget.
switch ( e->type() )
{
case QEvent::KeyPress:
- if ( myWatched && o == myWatched )
- {
+ if ( o == myWatched ) {
QKeyEvent* ke = (QKeyEvent*)e;
- int key = ke->key();
- QString ttf = myData->text();
QString text = ke->text();
- if ( isVisible() )
- {
- switch ( key )
- {
- case Qt::Key_Escape:
- hide();
- return true;
- case Qt::Key_Backspace:
- ttf.chop( 1 );
- break;
- case Qt::Key_Return:
- case Qt::Key_Enter:
- findNext();
- return true;
- default:
- if ( text.isEmpty() || !text[0].isPrint() )
- return QFrame::eventFilter( o, e );
- ttf += text;
- }
- }
- else
- {
- if ( text.isEmpty() || !isEnabled() || !text[0].isPrint() || myActivators == None )
- return QFrame::eventFilter( o, e );
-
+ if ( !isVisible() ) {
if ( text.startsWith( '/' ) && myActivators & SlashKey )
{
myData->clear();
find();
return true;
}
- else if ( !( myActivators & PrintKey ) )
+ else if ( myActivators & PrintKey && text[0].isPrint() )
{
- return QFrame::eventFilter( o, e );
- }
-
- ttf = text;
- show();
+ myData->setText( text );
+ find( text );
+ return true;
+ }
}
- myData->setText( ttf );
- find( ttf );
}
- break; // case QEvent::KeyPress
+ break;
case QEvent::FocusIn:
case QEvent::FocusOut:
if ( focused() )
- {
myAutoHideTimer->stop();
- }
else if ( isVisible() && isAutoHideEnabled() )
- {
myAutoHideTimer->start();
- }
break;
default:
break;
\param parent parent widget
*/
QtxTreeView::QtxTreeView( QWidget* parent )
-: QTreeView( parent )
+ : QTreeView( parent ),
+ myKeySearchEnabled( true )
{
setHeader( new Header( false, this ) );
}
\param parent parent widget
*/
QtxTreeView::QtxTreeView( const bool enableSortMenu, QWidget* parent )
-: QTreeView( parent )
+ : QTreeView( parent ),
+ myKeySearchEnabled( true )
+
{
setHeader( new Header( enableSortMenu, this ) );
}
emit( sortingEnabled( enabled ) );
}
+/*!
+ \brief Returns true if the keyboard search is enabled.
+*/
+bool QtxTreeView::isKeyboardSearchEnabled() const
+{
+ return myKeySearchEnabled;
+}
+
+/*!
+ \brief Enable/disable the keyboard search.
+*/
+void QtxTreeView::setKeyboardSearchEnabled( bool on )
+{
+ myKeySearchEnabled = on;
+}
+
+/*!
+ \brief Moves to and selects the item best matching the string search.
+ If keyboard search is disabled or no item is found nothing happens.
+ \param search is pattern string
+*/
+void QtxTreeView::keyboardSearch( const QString& search )
+{
+ if ( isKeyboardSearchEnabled() )
+ QAbstractItemView::keyboardSearch( search );
+}
+
#include <QtxTreeView.moc>
void expandTo( const QModelIndex& );
+ bool isKeyboardSearchEnabled() const;
+ void setKeyboardSearchEnabled( bool );
+
+ void keyboardSearch( const QString& );
+
protected slots:
void onHeaderClicked();
void rowsAboutToBeRemoved( const QModelIndex&, int, int );
private:
void emitSortingEnabled( bool );
+ private:
+ bool myKeySearchEnabled;
+
friend class QtxTreeView::Header;
};