[Haskell-cafe] GUI library

Job Vranish jvranish at gmail.com
Tue Sep 1 11:59:43 EDT 2009


If you're already used to C++ Qt and PyQt, qtHaskell should be relatively
straightforward (though probably with a few gotchas).
You could download qtHaskell and look at the examples to get an idea for the
feel of it. If you're already used to Qt they should look familiar.

Subclassing _is_ done a little weird:

First you declare a dummy datatype:

data MyQPushButton = MyQPushButton

And then you use the qSubClass function:

myQPushButton :: String -> IO (QPushButton MyQPushButton)
myQPushButton s = qSubClass $ qPushButton1 s

The type signature here is necessary. It's the only thing that forces the
new (QPushButton a) to be a QPushButton MyQPushButton.

Then you can use your subclassed buttons like so:

main :: IO ()
main = do
    app <- qApplication
    dialog <- qDialog
    button1 <- myQPushButton "Click for Stuff"
    qObject_connectSlot1 button1 "clicked()" button1 "click()" $
on_pbutton_clicked dialog
    mainLayout <- qVBoxLayout
    qLayout_addWidget mainLayout button1
    qWidget_setLayout dialog mainLayout
    qWidget_setWindowTitle dialog "Stuff Test"
    ok <- qDialog_exec dialog
    return()

on_pbutton_clicked :: QDialog () -> QPushButton MyQPushButton -> IO ()
on_pbutton_clicked _dlg _this  = do
    mb <- qMessageBox1 _dlg
    qMessageBox_setText mb $ "Stuff"
    qWidget_show mb
    return ()

Hmmm, though it doesn't look like you can currently overload methods of your
parent class, usually you don't need too though as you can just tie into a
signal (so you still can do things like paint). Though I'm kinda suprised I
didn't notice this before, I'll have to email the guy and see if this is
actually an issue.

Also, qtHaskell doesn't fully support all the Qt widgets (though it covers
most of them) but there is a new version coming out soon that should be more
complete.

Overall qtHaskell has served my perposes well.

There is also a good listing of GUI toolkits for Haskell at
http://www.haskell.org/haskellwiki/Applications_and_libraries/GUI_libraries

- Job

On Tue, Sep 1, 2009 at 1:49 AM, Michael Mossey <mpm at alumni.caltech.edu>wrote:

> Thanks for the info. Interesting. I'm already familiar with C++ Qt and also
> PyQt. I am also a fan of Qt.
>
> However, as a beginner to Haskell, I want to be sure I don't get myself
> into trouble. I hope that qtHaskell is straightforward.
>
> Qt depends on deriving user classes. How is this handled in qtHaskell?
>
> Thanks,
>
> -Mike
>
>
> Job Vranish wrote:
>
>> I recommend qtHaskell.
>> I am a big fan of Qt in general. It has good documentation and extensive
>> examples, is very well designed, and has a good license. I'd even say the
>> C++ version is good choice for beginners (certainly easier to understand/use
>> than say GTK).
>> The qtHaskell bindings are also pretty good. The documentation and
>> examples are not as extensive, but you can usually use the C++ documentation
>> to fill in the gaps.
>> Being already familiar with C++ Qt, using qtHaskell was a snap. However,
>> if you're unfamiliar with both Qt and Haskell it will probably be confusing
>> at first. Though I'd bet money the GTK bindings aren't any better in that
>> regard.
>> I'd still say you'd be more productive with qtHaskell in the long run.
>>
>> - Job
>>
>>
>> On Sat, Aug 29, 2009 at 11:03 AM, Michael Mossey <mpm at alumni.caltech.edu<mailto:
>> mpm at alumni.caltech.edu>> wrote:
>>
>>    I want to choose a GUI library for my project. Some background: I'm
>>    a beginner to functional programming and have been working through
>>    Haskell books for a few months now. I'm not just learning Haskell
>>    for s**ts and giggles; my purpose is to write
>>    music-composition-related code; in particular, I want to write a
>>    graphical musical score editor. (Why write my own editor, you may
>>    ask? Because I want to fully integrate it with
>>    computer-assisted-composition algorithms that I plan to write, also
>>    in Haskell.) I decided to use Haskell for its great features as a
>>    functional programming language.
>>
>>    Regarding a choice of GUI library, I want these factors:
>>
>>    - it needs to provide at a minimum a drawing surface, a place I can
>>    draw lines and insert characters, in addition to all the standard
>>    widgets and layout capabilities we have to come to expect from a GUI
>>    library.
>>
>>    - This is a Windows application.
>>
>>    - it needs to be non-confusing for an intermediate-beginner
>>    Haskeller. Hopefully good documentation and examples will exist on
>>    the web.
>>
>>    - It might be nice to have advanced graphics capability such as Qt
>>    provides, things like antialiasied shapes, and a canvas with
>>    efficient refresh (refereshes only the area that was exposed, and if
>>    your canvas items are only primitives, it can do refreshes from
>>    within C++ (no need to touch your Haskell code at all). However I'm
>>    wondering if qtHaskell fits my criteria "well-documented" and "lots
>>    of examples aimed at beginners".
>>
>>    Thanks,
>>    Mike
>>    _______________________________________________
>>    Haskell-Cafe mailing list
>>    Haskell-Cafe at haskell.org <mailto:Haskell-Cafe at haskell.org>
>>    http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090901/05aa7189/attachment.html


More information about the Haskell-Cafe mailing list