Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, May 2008
list view and keyboardSearch


Message 1 in thread

I apologize if this is a basic question - I'm a qt newbie.

I'm using a QListView to as a display widget for a large amount of text 
that resides in a database (QPlainTextEdit would require me to load way 
too much data at once - I need to bring pieces of it in as needed).  
It's pretty much working, but I'm having trouble with a couple of the 
details, and I'm wondering if anyone has suggestions.

1.  If the user types a key while the QListView has focus, it will begin 
a linear search for the text.  This causes the QListView to load in 
every line from the model to search it.  It's essential that this never 
happen because the model is enormous.  Is there a way to disable 
keyboardSearch short of subclassing QListView and reimplementing the 
function to do nothing?  If I do that, can I still use designer to 
create and layout my QListView subclass?


2.  By switching from QPlainTextEdit to QListView, I've taken away 
ability to select a string of text with the cursor.  It's a read-only 
display widget, so the main application of this would be to select a 
range of text to copy to the clipboard.  Are there any pre-existing 
delegates that would support this sort of thing, or do I have to roll my 
own?  Is there an example of this anywhere?

Thanks in advance!
    Jeff

--
 [ signature omitted ] 

Message 2 in thread

I've found a solution to my question #2.  If my model always returns 
false for setData() and my delegate calls setReadOnly(true) on the 
editor (provided it's a QLineEdit), then I get the behavior I want.  Is 
that the recommended way to do this sort of thing?

I'm still stuck on #1, though.
    Thanks,
    Jeff

Jeff Gibson wrote:
> I apologize if this is a basic question - I'm a qt newbie.
>
> I'm using a QListView to as a display widget for a large amount of 
> text that resides in a database (QPlainTextEdit would require me to 
> load way too much data at once - I need to bring pieces of it in as 
> needed).  It's pretty much working, but I'm having trouble with a 
> couple of the details, and I'm wondering if anyone has suggestions.
>
> 1.  If the user types a key while the QListView has focus, it will 
> begin a linear search for the text.  This causes the QListView to load 
> in every line from the model to search it.  It's essential that this 
> never happen because the model is enormous.  Is there a way to disable 
> keyboardSearch short of subclassing QListView and reimplementing the 
> function to do nothing?  If I do that, can I still use designer to 
> create and layout my QListView subclass?
>
>
> 2.  By switching from QPlainTextEdit to QListView, I've taken away 
> ability to select a string of text with the cursor.  It's a read-only 
> display widget, so the main application of this would be to select a 
> range of text to copy to the clipboard.  Are there any pre-existing 
> delegates that would support this sort of thing, or do I have to roll 
> my own?  Is there an example of this anywhere?
>
> Thanks in advance!
>    Jeff
>
> -- 
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>

--
 [ signature omitted ] 

Message 3 in thread

Ill answer #1.a (more of a question to designer)

If you can create a derived class of QListView, simply use QListView in
designer, then use "Promte To" via the Right mouse button on the view,
and set it to use your new class...

To fix the actuall problem... well let me get back later on that :)

Scott

> -----Original Message-----
> From: Jeff Gibson [mailto:jsg72@xxxxxxx]
> Sent: Monday, May 19, 2008 3:04 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: list view and keyboardSearch
> 
> I've found a solution to my question #2.  If my model always returns
> false for setData() and my delegate calls setReadOnly(true) on the
> editor (provided it's a QLineEdit), then I get the behavior I want.
Is
> that the recommended way to do this sort of thing?
> 
> I'm still stuck on #1, though.
>     Thanks,
>     Jeff
> 
> Jeff Gibson wrote:
> > I apologize if this is a basic question - I'm a qt newbie.
> >
> > I'm using a QListView to as a display widget for a large amount of
> > text that resides in a database (QPlainTextEdit would require me to
> > load way too much data at once - I need to bring pieces of it in as
> > needed).  It's pretty much working, but I'm having trouble with a
> > couple of the details, and I'm wondering if anyone has suggestions.
> >
> > 1.  If the user types a key while the QListView has focus, it will
> > begin a linear search for the text.  This causes the QListView to
> load
> > in every line from the model to search it.  It's essential that this
> > never happen because the model is enormous.  Is there a way to
> disable
> > keyboardSearch short of subclassing QListView and reimplementing the
> > function to do nothing?  If I do that, can I still use designer to
> > create and layout my QListView subclass?
> >
> >
> > 2.  By switching from QPlainTextEdit to QListView, I've taken away
> > ability to select a string of text with the cursor.  It's a
read-only
> > display widget, so the main application of this would be to select a
> > range of text to copy to the clipboard.  Are there any pre-existing
> > delegates that would support this sort of thing, or do I have to
roll
> > my own?  Is there an example of this anywhere?
> >
> > Thanks in advance!
> >    Jeff
> >
> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx
> with
> > "unsubscribe" in the subject or the body.
> > List archive and information:
http://lists.trolltech.com/qt-interest/
> >
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 4 in thread

I just stepped through the code running the following example:
int main( int argc, char ** argv)
{
	QApplication appl( argc, argv );

	QStringListModel model( QStringList() << "AAAA" << "BBBB" <<
"CCCC" << "DDDD" );
	QListView view;
	view.setModel( &model );
	view.show();

	appl.exec();
}

And there is no way that I found to disable keyboardSearch..

I recommend a bug/task be filed, where a property would be added to
QAbstractItemView that would allow for this to be disabled (or enabled,
and have it turned on by default)

Something like
view.setEnableKeyboardSearch( false );


But... I did find 2 solutions...
1) use the following QListView
class NSListView : public QListView
{
public:
	NSListView() : QListView()
	{
	}

	virtual void keyboardSearch( const QString & )
	{
	}
};

And your golden :) But you new that...

Another solution, create a simple custom delegate, that always returns
true for the editorEvent

class NSItemDelegate : public QItemDelegate
{
public:
	NSItemDelegate() : QItemDelegate()
	{
	}

	virtual bool editorEvent(QEvent *event,
                                QAbstractItemModel *model,
                                const QStyleOptionViewItem &option,
                                const QModelIndex &index)
	{
		return true;
	}

};

And simply call view.setItemDelegate( new NSItemDelegate() );

Essentially, the code in the view that says "key hit go search" checks
to see if the key starts an editing session first.

Frankly, they both seem hackish to me, however, from a Model View
Delegate architecture point of view, I like the second one better... but
I could be convinced the first one is better..

Hope this helps

Scott





> -----Original Message-----
> From: Scott Aron Bloom [mailto:Scott.Bloom@xxxxxxxxxxxx]
> Sent: Monday, May 19, 2008 3:09 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: RE: list view and keyboardSearch
> 
> Ill answer #1.a (more of a question to designer)
> 
> If you can create a derived class of QListView, simply use QListView
in
> designer, then use "Promte To" via the Right mouse button on the view,
> and set it to use your new class...
> 
> To fix the actuall problem... well let me get back later on that :)
> 
> Scott
> 
> > -----Original Message-----
> > From: Jeff Gibson [mailto:jsg72@xxxxxxx]
> > Sent: Monday, May 19, 2008 3:04 PM
> > To: qt-interest@xxxxxxxxxxxxx
> > Subject: Re: list view and keyboardSearch
> >
> > I've found a solution to my question #2.  If my model always returns
> > false for setData() and my delegate calls setReadOnly(true) on the
> > editor (provided it's a QLineEdit), then I get the behavior I want.
> Is
> > that the recommended way to do this sort of thing?
> >
> > I'm still stuck on #1, though.
> >     Thanks,
> >     Jeff
> >
> > Jeff Gibson wrote:
> > > I apologize if this is a basic question - I'm a qt newbie.
> > >
> > > I'm using a QListView to as a display widget for a large amount of
> > > text that resides in a database (QPlainTextEdit would require me
to
> > > load way too much data at once - I need to bring pieces of it in
as
> > > needed).  It's pretty much working, but I'm having trouble with a
> > > couple of the details, and I'm wondering if anyone has
suggestions.
> > >
> > > 1.  If the user types a key while the QListView has focus, it will
> > > begin a linear search for the text.  This causes the QListView to
> > load
> > > in every line from the model to search it.  It's essential that
> this
> > > never happen because the model is enormous.  Is there a way to
> > disable
> > > keyboardSearch short of subclassing QListView and reimplementing
> the
> > > function to do nothing?  If I do that, can I still use designer to
> > > create and layout my QListView subclass?
> > >
> > >
> > > 2.  By switching from QPlainTextEdit to QListView, I've taken away
> > > ability to select a string of text with the cursor.  It's a
> read-only
> > > display widget, so the main application of this would be to select
> a
> > > range of text to copy to the clipboard.  Are there any
pre-existing
> > > delegates that would support this sort of thing, or do I have to
> roll
> > > my own?  Is there an example of this anywhere?
> > >
> > > Thanks in advance!
> > >    Jeff
> > >
> > > --
> > > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx
> > with
> > > "unsubscribe" in the subject or the body.
> > > List archive and information:
> http://lists.trolltech.com/qt-interest/
> > >
> >
> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx
> with
> > "unsubscribe" in the subject or the body.
> > List archive and information:
http://lists.trolltech.com/qt-interest/
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 5 in thread

Thanks, that works.  I picked the first method, and your previous mail 
is what I needed to get it working with designer.

Regarding my solution to the second question, I have a delegate that I 
think is quite a hack, but I don't know of a better way to do it.  The 
two problems that I'm trying to solve is that I want a read-only editor 
(i.e., so text can be selected but not changed) and I have lines of text 
that are color-coded by another field in the database.  The model 
returns the text color in data( Qt::ForegroundRole ), which works great 
in the view, but not in the editor (the editor never consults the model 
for the color).  Is there a better way to do the following?
    Thanks,
    Jeff


void
LogDelegate::setEditorData( QWidget* editor, const QModelIndex& index) 
const
{
  QStyledItemDelegate::setEditorData(editor, index);
   
  QVariant value = index.data( Qt::ForegroundRole );
  if(qVariantCanConvert<QBrush>(value)) {
     
    QPalette palette;
    palette.setColor( QPalette::Text,
                      qvariant_cast<QBrush>( value ).color() );
    editor->setPalette( palette );
     
  }

  QLineEdit* lineEdit = qobject_cast<QLineEdit*>(editor);
  if(lineEdit) {
    lineEdit->setReadOnly( true );
  }
   
}


Scott Aron Bloom wrote:
> I just stepped through the code running the following example:
> int main( int argc, char ** argv)
> {
> 	QApplication appl( argc, argv );
>
> 	QStringListModel model( QStringList() << "AAAA" << "BBBB" <<
> "CCCC" << "DDDD" );
> 	QListView view;
> 	view.setModel( &model );
> 	view.show();
>
> 	appl.exec();
> }
>
> And there is no way that I found to disable keyboardSearch..
>
> I recommend a bug/task be filed, where a property would be added to
> QAbstractItemView that would allow for this to be disabled (or enabled,
> and have it turned on by default)
>
> Something like
> view.setEnableKeyboardSearch( false );
>
>
> But... I did find 2 solutions...
> 1) use the following QListView
> class NSListView : public QListView
> {
> public:
> 	NSListView() : QListView()
> 	{
> 	}
>
> 	virtual void keyboardSearch( const QString & )
> 	{
> 	}
> };
>
> And your golden :) But you new that...
>
> Another solution, create a simple custom delegate, that always returns
> true for the editorEvent
>
> class NSItemDelegate : public QItemDelegate
> {
> public:
> 	NSItemDelegate() : QItemDelegate()
> 	{
> 	}
>
> 	virtual bool editorEvent(QEvent *event,
>                                 QAbstractItemModel *model,
>                                 const QStyleOptionViewItem &option,
>                                 const QModelIndex &index)
> 	{
> 		return true;
> 	}
>
> };
>
> And simply call view.setItemDelegate( new NSItemDelegate() );
>
> Essentially, the code in the view that says "key hit go search" checks
> to see if the key starts an editing session first.
>
> Frankly, they both seem hackish to me, however, from a Model View
> Delegate architecture point of view, I like the second one better... but
> I could be convinced the first one is better..
>
> Hope this helps
>
> Scott
>
>
>
>
>
>   
>> -----Original Message-----
>> From: Scott Aron Bloom [mailto:Scott.Bloom@xxxxxxxxxxxx]
>> Sent: Monday, May 19, 2008 3:09 PM
>> To: qt-interest@xxxxxxxxxxxxx
>> Subject: RE: list view and keyboardSearch
>>
>> Ill answer #1.a (more of a question to designer)
>>
>> If you can create a derived class of QListView, simply use QListView
>>     
> in
>   
>> designer, then use "Promte To" via the Right mouse button on the view,
>> and set it to use your new class...
>>
>> To fix the actuall problem... well let me get back later on that :)
>>
>> Scott
>>
>>     
>>> -----Original Message-----
>>> From: Jeff Gibson [mailto:jsg72@xxxxxxx]
>>> Sent: Monday, May 19, 2008 3:04 PM
>>> To: qt-interest@xxxxxxxxxxxxx
>>> Subject: Re: list view and keyboardSearch
>>>
>>> I've found a solution to my question #2.  If my model always returns
>>> false for setData() and my delegate calls setReadOnly(true) on the
>>> editor (provided it's a QLineEdit), then I get the behavior I want.
>>>       
>> Is
>>     
>>> that the recommended way to do this sort of thing?
>>>
>>> I'm still stuck on #1, though.
>>>     Thanks,
>>>     Jeff
>>>
>>> Jeff Gibson wrote:
>>>       
>>>> I apologize if this is a basic question - I'm a qt newbie.
>>>>
>>>> I'm using a QListView to as a display widget for a large amount of
>>>> text that resides in a database (QPlainTextEdit would require me
>>>>         
> to
>   
>>>> load way too much data at once - I need to bring pieces of it in
>>>>         
> as
>   
>>>> needed).  It's pretty much working, but I'm having trouble with a
>>>> couple of the details, and I'm wondering if anyone has
>>>>         
> suggestions.
>   
>>>> 1.  If the user types a key while the QListView has focus, it will
>>>> begin a linear search for the text.  This causes the QListView to
>>>>         
>>> load
>>>       
>>>> in every line from the model to search it.  It's essential that
>>>>         
>> this
>>     
>>>> never happen because the model is enormous.  Is there a way to
>>>>         
>>> disable
>>>       
>>>> keyboardSearch short of subclassing QListView and reimplementing
>>>>         
>> the
>>     
>>>> function to do nothing?  If I do that, can I still use designer to
>>>> create and layout my QListView subclass?
>>>>
>>>>
>>>> 2.  By switching from QPlainTextEdit to QListView, I've taken away
>>>> ability to select a string of text with the cursor.  It's a
>>>>         
>> read-only
>>     
>>>> display widget, so the main application of this would be to select
>>>>         
>> a
>>     
>>>> range of text to copy to the clipboard.  Are there any
>>>>         
> pre-existing
>   
>>>> delegates that would support this sort of thing, or do I have to
>>>>         
>> roll
>>     
>>>> my own?  Is there an example of this anywhere?
>>>>
>>>> Thanks in advance!
>>>>    Jeff
>>>>
>>>> --
>>>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx
>>>>         
>>> with
>>>       
>>>> "unsubscribe" in the subject or the body.
>>>> List archive and information:
>>>>         
>> http://lists.trolltech.com/qt-interest/
>>     
>>> --
>>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx
>>>       
>> with
>>     
>>> "unsubscribe" in the subject or the body.
>>> List archive and information:
>>>       
> http://lists.trolltech.com/qt-interest/
>   
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>> "unsubscribe" in the subject or the body.
>> List archive and information: http://lists.trolltech.com/qt-interest/
>>     
>
>   

--
 [ signature omitted ]