[Qt-interest] Painting question

Stephen Kelly steveire at gmail.com
Sun Aug 16 14:13:56 CEST 2009


Robert Hairgrove wrote:

> I would like to paint on a widget but only AFTER starting a drag
> operation. The documentation says not to use QPainter except inside a
> widget's paintEvent() function (there is a way on Linux, but not on
> Windows).
> 
> My scenario is this: in a class derived from QTableView, I display a
> schedule of lessons with individual students' names displayed in a
> timetable. I have successfully implemented the drag & drop functionality
> which allows the user to change lessons by dragging the students around
> in the timetable.
> 
> What I would like to do is to display a little green dot or icon in the
> available spaces to show the user the location of the available slots
> depending on the student's free hours for the lesson which is being
> dragged.

I'd say you when you start the drag, do model->setData(idx, Qt::green, 
Qt::DecorationRole), then when you finish it, do model->setData(idx, 
theDecorationThatWasThereBefore, Qt::DecorationRole).

Would that work?

> 
> I am looking for suggestions on the best possible approach (or any
> approach which works, for that matter). Since the QDrag::exec() function
> is a blocking function, I don't think I can use QPainter once it has
> started ... or is it possible?
> 
> Thanks!




More information about the Qt-interest-old mailing list