Adding Scrollbars to a QFrame in Qt

September 10th, 2007 by exhuma.twn

Many things are very easy to accomplish in Qt. Qt’s designer is a great help with that. But the is no option to simply “enable” scrollbars for a frame. Also, the QScrollArea can nowhere be found in the designer. The solution is actually quite simple:

  1. Add the component you want to be scrollable (QFrame, QLabel, …) in the designer as usual
  2. In the application code:
    1. Create a new QScrollArea
    2. Set the parent of the widget you created in the designer to “None”
    3. Set the widget of the QScrollArea to the widget from step 1
    4. Insert the QScrollArea to you ui

And here’s some example code (boiled down to the essentials):

sa = QtGui.QScrollArea()
self.ui.myWidget.setParent(None)
sa.setWidget(self.ui.myWidget)
self.ui.vboxlayout1.insertWidget(0, sa)

You would probably write this somewhere in you application-constructor right after you call setupUi.

This will insert the scroll area at the top of vboxlayout1 (see the doc for insertWidget). You can of course also use addWidget.

It’s a shame that there’s no direct support for QScrollArea in designer. Maybe we will see it in some future release.

An example for C++ can be found in the Qt Forums.

Posted in Python | 2 Comments »

VIM rc-file

August 10th, 2007 by exhuma.twn

Due to inane network restrictions I am maintaining several copies of my vimrc file. I would syncronize it though other means. Alas, the restrictions not only cover the network. So I have to resort to simply posting it here.

This is not meant to be an explanation of vim configuration file. However, it contains lots of comments, and might prove a good primer/starting-point. Eventually I will also include other modifications I made in my vim-home-folder as they are either used in the vimrc or just plain useful 😉

Read the rest of this entry »

Posted in Babble, Coding Voodoo | 2 Comments »

Ohloh Open Source Statistics

July 26th, 2007 by exhuma.twn

ohlo language statsOholoh is a site that keeps code statistics of open-source projetcs. It’s very interesting to browse though the different projects and look at their metrics.

It can also be a nice incentive to get people do commit on a regular basis, as it adds a sort of healthy competition to the development cycle.

Anyhow…. Great idea, and it already keeps track of quite a number of projects.

Posted in Coding Voodoo | No Comments »

Visual Basic Sucks!

July 19th, 2007 by exhuma.twn

That’s all I have to say!

Posted in Coding Voodoo | No Comments »

Deploying PyQt applications on Windows

July 12th, 2007 by exhuma.twn

My preferred way to deploy python applications on Windows is to use py2exe.

py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation.

If you run in trouble with sip, read on…
Read the rest of this entry »

Posted in Python | 1 Comment »

OverkillFlickr: a Flickr API interface for PHP5

July 9th, 2007 by wickeddoc

I create a small Flickr API interface for PHP5 which takes advantage of the Overloading feature of PHP5.

Using the __call method we can dynamically create an interface to all the Flickr API functions using only a very small script.

The name of the class is purely ironic as it is a very simple and easy-to-use class and far from Overkill.

Read the rest of this entry »

Posted in PHP | 7 Comments »

Writing Qt apps in python

July 2nd, 2007 by exhuma.twn

Writing Qt apps in Python with Qt3 worked. Somewhat. I never found the energy to get it all set up. Finally with Qt4 we have something that “just works”. At least on Ubuntu and Windows (haven’t tested anywhere else).

Yes, since version 4, trolltech finally decided to release Qt as well under the GPL. To most of you it’s all old news. But hey…. just felt like writing it down again 😉

The problems with SIP are finally gone. So you just install python, Qt4 and pyqt4 and off you go.

Read the rest of this entry »

Posted in Python | No Comments »

Using the ltree module in PostgreSQL

June 27th, 2007 by exhuma.twn

PostgreSQL offers the very interesting module ltree. It’s used to represent a tree structure within the database. One could represent a tree quite easily as a table which references itself. However, if you ever went along that road, you will know that it becomes very slow with larger trees. In addition, the SQL queries that reference themselves are very unhandy.

If you want to know more, what ltree can do for you, I suggest you go ahead and read the usage examples on the ltree homepage.

Installing ltree

This is the part that eluded me. On the homepage it only states:

  cd contrib/ltree
  make
  make install
  make installcheck

Read the rest of this entry »

Posted in Coding Voodoo | 2 Comments »

Runnning a twisted application as windows service

June 27th, 2007 by exhuma.twn

Currently I am a bit busy, so I will just dump the post I found on usenet. Eventually I will clean it up…

On Wed, 22 Oct 2003 12:24:42 -0600
"Justin Johnson" <justinjohnson@fastmail.fm> wrote:

> The general consensus on the mailing list archives seems to be that
> I'd need to setup my code to not require twistd but just run
> standalone.

Uh. *Maybe* that's the consensus, but it's not actually correct. You can
have a tap or tac run as a NT service.

Lets say you have  a script "server.py" that is runnable with "twistd
-y", you can do (and similar code will work for TAPs):
import sys, os
import win32serviceutil, win32service

class MyService(win32serviceutil.ServiceFramework):
    """NT Service."""

    _svc_name_ = "MyService"
    _svc_display_name_ = "MyService server"

    def SvcDoRun(self):
        import server
        f = open(os.path.join(server.rootPath, "cyberhigh.log"), 'a')
        from twisted.python.log import startLogging
        from twisted.application.app import startApplication
        from twisted.internet import reactor
        startLogging(f)
        startApplication(server.application, 0)
        reactor.run()

    def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        from twisted.internet import reactor
        reactor.stop()

if __name__ == '__main__':</pre>
    win32serviceutil.HandleCommandLine(MyService)</pre>
--
Itamar Shtull-Trauring    http://itamarst.org/
Available for Python & Twisted consulting


Posted in Python | No Comments »

Next Entries »

Pages

Recent Posts

Categories

Links


Archives

Meta