Harsh J

Memoirs of a QWERTY Keyboard

Archive for the ‘Qt’ tag

Fall of the Sulks

2 comments

My undergraduate project is complete, with a few glitches to cover up. It ain’t much for now, but I guess its enough to make a sizable impact. I’d like to say that PyMT is an excellent library, and I can’t thank the developers behind it enough for their work so far (They’ve written a tracker too now, you gotta check that out). Maybe I shall contribute to it in near future, provided I have the time and skill. Contributing by code is something I only recently learned and its not wise to be hasty. Plus, there’s loads of math involved ;)

Randomly placed warning for a random post.

On the Qt front, I have this draft of a PyQt4 + Designer tutorial lying around for 7 months and it still doesn’t feel complete (alright, am lazy to make it so). Maybe I should do another screenshot + diagramming session and see if that turns out satisfactory. Something brewing in my mind for a feature in KDE 4.5 has pushed me to handle XML with the same toolkit – and writing SAX parsers is ugly, even more so if its C++. I wish I didn’t have to do that, I hate writing readers of tags and the characters between them – it always conks out someday or sometime.

Fall of the Hulks Poster

Poster to 'Fall of the Hulks'

Am addicted to comics these days, more than I’ve been to TV shows or movies (You may count “Lost” and ‘The Matrix’ as exclusions to that). Let’s talk about ‘Fall of the Hulks‘. Its twisted in its story, not many have great guesses on the new Red-Hulk (or Rulk) character and the entire screenplay is Nick Fury-esque; Apparently the story following this arc will have all major heroes of the Marvel Universe hulked up, which would be totally awesome to read (the covers are making me ogle already). For now Siege and Realm of Kings satisfy the addiction hunger. I’m not much of a fan when it comes to DC, having read pretty out-dated stuff only (such as Death of Superman or Knightfall), and thus am not quite enjoying the over-stretched Blackest Night titles they have everywhere. Karthik would not be happy with this, but fear not my friend – the completionist in me won’t give up till it ends.

Re-read Mostly Harmless and am dying to purchase and read ‘And Another Thing…‘ by Eoin Colfer but it seems too expensive even now. Will get it in the sale season probably, and read it at the Eloor libraries until that happens. H2G2 and its associated books are a must read for anyone with brains and capacity for painful-cheeks humor.

Until the next update!

Written by Harsh

March 8th, 2010 at 8:04 pm

Posted in Personal

Tagged with , , , , ,

Sorting entries in a QStringList Case-insensitively

4 comments

This post is simply a snippet-post for the users of Nokia’s Qt C++ cross-platform toolkit.

While writing some C++ code (after 2 long years since I last wrote them for academic reasons), I had this simple issue of sorting a QStringList in a case-insensitive manner. Normally, there exists a QStringList::sort() function that does the sorting of the strings stored in it in a case-sensitive manner, and is very fast at it. But Qt does not provide a way to perform the sort in a non case-sensitive manner, although it has hints on how to in the class’ documentation.

Being mostly a PyQt/PySide user who uses inbuilt Python lists to do all list-work, here’s how its apparently done in Qt/C++, using a QtCore class called QMap:

#include <QtCore/QStringList>
#include <QtCore/QMap>

void sortNonCaseSensitive( QStringList &sList ) {
    ///  Sorts the passed sList non-case-sensitively.
    ///  (Preserves the cases! Just doesn't use them
    ///  while sorting.)
    QMap<QString, QString> strMap;
    foreach ( QString str, sList ) {
        strMap.insert( str.toLower(), str );
    }
    sList = strMap.values();
}

That’s it.

Written by Harsh

October 24th, 2009 at 10:54 pm

The case of the non-exiting Mozilla Firefox

9 comments

Being a KDE user has its ups and downs. The ups are that its beautiful, has a very wide and usable range of applications, updates often for bugfixes, and is generally very customizable. The downs are a few – with the Firefox+GTK integration being one of them. It makes your browser look UGLY! Of course, there are Qt-friendly browsers like Opera and Konqueror, even Arora, but these hardly work well with many sites, especially those of Google (Wave, for example). I’m not gonna delve into that subject, since this post is about using Firefox on KDE 4 (version 4.3.x).

You might have heard of the GTK engine that themes for Qt, known as gtk-engine-qt on most distributions (or with -kde4 suffix, if thats how they’ve integrated). This helps all GTK applications look great on KDE by providing *near* native look and feel. So I install that and smile, happy that my entire K Desktop is as I want it – dark, without gloss and perfectly usable with certain plasma widgets. That is until I notice my Firefox simply does not close itself when asked to, and hangs instead.

At first one would think its due to a plugin, or an extension, probably something added on that is causing it to hang when its supposed to terminate. Even the KB article at Mozillazine supports that fact. Perhaps its a popular reason, but I tried and it didn’t solve the issue for me. I jumped a few steps out of frustration and went on to move my .mozilla directory to a different name, just to see if it was a profile-related issue, and it still refused to close, driving me mad having to `killall firefox` it each time since it always hung at exit. So I switched to Opera and used it with horrible colors – Pages appeared normally as they would be rendered but the forms and other things just didn’t go well with my dark color scheme (Eclipse), making it appear like the image below, unreadable and thus untypable upon.

Unreadable, Unseeable - The form elements as they appear in my Opera (While using a dark color scheme in the DE)

Unreadable, Unseeable - The form elements as they appear in my Opera (While using a dark color scheme in the DE)

The browser’s great otherwise, its fast and very customizable, but I couldn’t make any changes to these colors. I suppose one can achieve it by writing their own userstyle.css file but that is too much work. Used Opera until today, when I finally found this (pretty old) bug in the gtk-engine-qt project tracker. Uninstalled gtk-engine-qt and lo, all was normal again, closed fine and opened fine. Re-installed all plugins and extensions, and said bye-bye to Opera.

All I now miss is a native-looking dark theme with Oxygen icons, as my K Desktop contains. I’m making do with the Black Stratini theme as of now, it’s beautiful but I like the Oxygen icons better. 440 words for just the choice of browser on a dark theme, tch.

Written by Harsh

October 9th, 2009 at 10:02 am

PyQt – Signals, Slots and Layouts Tutorial

8 comments

Having seen how a simple PyQt application code looks, let’s delve into user-interaction. We’ll learn about Qt’s signal-to-slot connection model for processing input and other events, and layouts for proper placement of widgets on a window.

The PyQt Class Hierarchy

PyQt is completely built upon the Object-Oriented concepts, so it is important to understand how all classes are related to each other in it.

Almost all GUI classes extend upon their Abstract class which defines common behaviour for similar widgets. These abstract classes, or any widget class, inherit QWidget, the base class of all drawable GUI components. QWidget inherits QObject, a class that has nothing to do with GUI but forms the base class of every PyQt class and helps provide the framework-related features.

The following hierarchy diagram depicts this clearly for the QPushButton class:

The QPushButton Class Hierarchy

The QPushButton Class Hierarchy

The QPaintDevice class helps draw (or paint) things on the screen, thus its also used with anything that’s drawable – We’ll learn more about Painting in a later article.

References: QWidget
Read the rest of this entry »

Written by Harsh

May 14th, 2009 at 11:37 am

Posted in Software

Tagged with , , , , ,

Basics of PyQt

leave a comment

This is a total beginners-only post. In this post, I will talk about what PyQt is, what it does and what are its major components you should know about before you start thinking about developing with it. I’ve made a simple Google Docs presentation about these and its viewable below or in full screen at this link.

Read the rest of this entry »

Written by Harsh

April 29th, 2009 at 9:34 am

Posted in Software

Tagged with , , , ,