You are not logged in.

boyadg

Beginner

  • "boyadg" started this thread

Posts: 11

Location: Barcelona

  • Send private message

1

Wednesday, June 2nd 2004, 11:46am

KHistoryCombo

There's a place in my app where the user should insert an URL and I thought it would be nice if the app remembered last n URLs for the user and then tries to autocomplete the URL with the ones in the history (like Internet Explorer does).

After reading about the different input widgets, I thought that KHistoryCombo did everything I wanted. The problem is that at the moment, it does nothing of all this!

First I thought that the only thing I had to do was to set the insertionPolicy property to AtTop, but nothing happened.

Then I supposed that maybe I had to add the string manually, which I find a bit strange, because if the Widget is called a KHistoryCombo I think it should handle adding the strings to the history itself. The problem is that I didn't find any decent signal to connect the addToHistory() funcion with. I tested it with returnPressed and that works, but I think that the most logical moment to add the string to the history would be when the widget loses focus.

So I went off to find a "focusLost()" signal, but I can't seem to find one! The only thing I found was something about re-implementing the focusOut() event, but I believe that means I have to subclass the widget?

So now I'm asking:
Do I really have to (1) subclass the widget to capture when the user leaves the KHistoryCombo, and (2) then add the string "manually" with the addToHistory() function, and (3) when the app is closed, write the code to save the list of strings in the config?
If 1-3 are true, why is the widget called a KHistoryCombo, when all of the "History" code has to be written manually?

Surely I must be missing something here...

anda_skoa

Professional

Posts: 1,273

Location: Graz, Austria

Occupation: Software Developer

  • Send private message

2

Wednesday, June 2nd 2004, 1:52pm

RE: KHistoryCombo

Quoted

Originally posted by boyadg
Then I supposed that maybe I had to add the string manually, which I find a bit strange, because if the Widget is called a KHistoryCombo I think it should handle adding the strings to the history itself.

It can, if you allow it.
See setHandleSignals(bool)

As an application might want to check the input before adding it to the history (in order to have only vaild input in the history), the default behaviour is to let the application handle history adds.

Quoted

(1) subclass the widget to capture when the user leaves the KHistoryCombo

No, QLineEdit has a signal focusLost()


Quoted

(2) then add the string "manually" with the addToHistory() function

No, see above

Quoted

when the app is closed, write the code to save the list of strings in the config

Yes, you get a QStringList containing all items, which you can write easily using KConfig::writeEntry, or any other configuration backend you might want to use.

Cheers,
_
Qt/KDE Developer
Debian User