Friday, June 09, 2006

QWidget::contextMenuEvent()

KolourPaint places widgets on top of a KToolBar for its "Colour Box" (a great abuse of KToolBar, I know - I'll be looking at fixing this). Unfortunately, in Qt4, right clicking on a colour patch (e.g. the transparent or green, circled in red below):



no longer selects the background colour - it brings up the toolbar popup menu instead:


(neat "Lock Toolbars" option BTW)

It turns out that implementing QWidget::mousePressEvent() no longer stops your parent from receiving the right mouse press that would invoke contextMenuEvent(). Spotting the new contextMenuPolicy, I figured that I would just set my children widgets to Qt::NoContextMenu ("the widget does not feature a context menu"). Doesn't work.

They way I got around it was to get the children to eat/accept() the contextMenuEvent(). Another undocumented, subtle change between Qt3 and 4...

In the meantime, I have started porting KolourPaint4 to a new "kpPainter" that abstracts away QPainter (not committed to SVN yet). Rectangles now work and are no longer 1 pixel higher and wider than they should be. Eventually, this abstraction will allow me to dump the Qt graphics routines for a better graphics library.

3 comments:

ingwa said...

What's the relationship of KolourPaint and Krita, feature wise and vision wise?

jospoortvliet said...

ingwa: what about 'totally different' ;-)

compare MS paint to Photoshop, and you get the idea. kolourpaint is a great, fast, simple picture editor. very easy to use. Krita is much more, and not so easy to use. actually, some things are so easy and fast to do in kolourpaint, i use them both on the same pictures now and then...

Clarence Dang said...

QPixmap/QPainter problems:

* screen depth dependent - image quality is lost by editing on a 8/15/16-bit screen

* API behaviour changes dramatically depending on whether one has XRENDER or not on the current display

QImage/QPainter solves both problems but:

* still doesn't support drawing onto indexed 8-bit images

* doesn't support 16-bit images

* QImage -> QPixmap translation for displaying on the screen is too slow for realtime updates