Final part of my ~/research cleanup
1. slidelistviewselection – A widget in which item selection moves with animation from one item to another. I made this initially for an embedded device on which itemviews was too heavy.
2. skinnable mediaplayer – An example that shows how to create a skinnable Qt app (see my old blog post).
3. bubblelist – An example of how one can create a scrollable item in graphicsview (like QScrollArea which scrolls i.e positions a big widget)
4. lineeditwithclearbutton – Line edit with clear button (see my old blog post)
http://labs.trolltech.com/blogs/2007/06/06/lineedit-with-a-clear-button/
A habit that I picked up from my job at Trolltech was to put all my experimental code in a directory called research. Each project gets its own sub-directory there. We used to also have a similarly named folder in p4 depot and it was totally unmanageable. I wonder what happened to all that code after they moved to git – there were hundreds of very interesting code samples there.
Back to me, over the years (yeah, like past 4-5 years), I have abused my research directory for examples, bug reports, writeups, screenshots/videos, blog posts and I thought it’s about time I clean it up
. I have been cleaning up 10-15 subdirectories a day for the past week (I have ~100 more to go) and I have to admit I grossly overestimated the value of the stuff in there
. But here’s what I found worth sharing so far (all of them are Qt examples, of course):
- customfont – How to load and use custom fonts.
- mplayerembed – How to embed mplayer into your app and control movie play (X11 only)
- customnetworkreply – This lets you create custom url’s inside qt/webkit. For example, you can embed a myapp://give/me/some/stuff or a http://myapp/foo.png. Code inspired from assistant.
- textlayoutprimer – I wrote this one when I was trying to understand how laying out text works inside QTextEdit (using QTextLayout). More didactic than an usable example.
- translucentbackground – Translucent background example (Uses ARGB visuals, requires composition manager)
- clipboardwatcher – Displays content of clipboard/selection as they change. Very useful to test dnd. I think I stole initial parts of the code from a similar Qt example.
I am still figuring what is a good way to maintain all this sample/throw away code. I also have ~/tmp where I have code that I can nuke without any thought. Any suggestions? What do you do? A problem I have had is I never manage to find the right code samples when I need them. I have already found many dups when cleaning up!
When consulting for Hyves, we wanted a light-weight widget that displays html and animated gifs (for smileys) for the chat client and for tooltips. The option to use Qt/WebKit was out since we intended to create numerous instances of this widget (it consumed lots of memory) and the rendering was not as fast we would like. QLabel does not support animated gifs, so that was not an option either.
Instead of writing a basic html parser, layouter and renderer, I thought I can somehow trick QTextDocument into displaying animated gifs. You can see the basic idea in this kb but to get it working with animations wasn’t easy. One good thing about adding the feature to QTextDocument is that you can set it on QTextBrowser and QTextEdit.
Without further ado, get the code here. Label is a richtext label that does not support links or selection. TextBrowser is a browser that supports selection and links. TextEdit is an editor with support for undo/redo.
P.S. Thanks to Hyves for making it possible to actually publish this code; they released most of their code as GPL.
There are situations where you don’t want text to be selected and images to be dragged in your QWebView (See my previous post). Qt does not provide support out of the box, but this is fairly straightforward to do. I wrote a quick hack to demonstrate, get it here.