Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / qt / 2007-07

Caret problems

11 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Павел Ишенин

Hello, Items specific to the Qt widget set

I am trying to implement Caret functions like CreateCaret, DestroyCaret, ShowCaret, HideCaret. I looked at Qt classes and did not find apropriate methods to create caret. Yes, I can create control with caret but it is not the same. That functions mimics winapi. So I decided to implement Caret the same way as gtk widgetset do.

Caret in gtk is 2 pixmaps that showing with interval (one pixmap contains bg and second caret). So I thinked it would be easy to achive same on qt.

But I have problems.

When I am trying to draw on widget it becomes gray and all other painting is dissapeared (maybe becase i do this on timer event and not on paint event).

To draw on windget I am using this code:

        DC := TQtDeviceContext.Create(THandle(Self));
        SrcRect := Bounds(0, 0, Width, Height);
        DstRect := Bounds(X, Y - 1, Width, Height);
        DC.drawImage(@DstRect, AImage.Handle, @SrcRect);
        DC.Free;

What is more proper way to do this?

ps: you can test caret yourself. To do this apply patch, add SynEdit control to form, run application and press into synedit. You'll see what is wrong.

Best regards,
Paul Ishenin.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed... Name: qt_caret.patch
URL: <http://lists.lazarus.freepascal.org/pipermail/qt/attachments/20070710/02d4624c/attachment.ksh>

zeljko
to Павел Ишенин
????? ?????? wrote 7 lines
Hello, Items specific to the Qt widget set I am trying to implement Caret functions like CreateCaret, DestroyCaret, ShowCaret, HideCaret. I looked at Qt classes and did not find apropriate methods to create caret. Yes, I can create control with caret but it is not the same. That functions mimics winapi. So I decided to implement Caret the same way as gtk widgetset do.

you're right , it's not so easy to get caret out of qt (think that QTextCursor is nearest class), so mimicked code is the only solution.

Caret in gtk is 2 pixmaps that showing with interval (one pixmap contains bg and second caret). So I thinked it would be easy to achive same on qt.

There's implementation of TCaret for qt2 in QWindows unit of JVCL (CLX part), and I think that it's maded by one pixmap (used for caret only) + timer.It's written by Andreas Hausladen some years ago.

Show quoted text 6 lines
But I have problems. When I am trying to draw on widget it becomes gray and all other painting is dissapeared (maybe becase i do this on timer event and not on paint event).

definitelly, it must be painted inside paint event.

zeljko

Павел Ишенин
to zeljko
zeljko wrote 5 lines
There's implementation of TCaret for qt2 in QWindows unit of JVCL (CLX part), and I think that it's maded by one pixmap (used for caret only) + timer.It's written by Andreas Hausladen some years ago.

Big thanks for hint.

Show quoted text 9 lines
> But I have problems. > > When I am trying to draw on widget it becomes gray and all other > painting is dissapeared (maybe becase i do this on timer event and not > on paint event). > definitelly, it must be painted inside paint event.

That should be reason.

Thanks.

Best regards,
Paul Ishenin.

Paul Ishenin
to zeljko: you're right , it's not so easy to get caret out of qt (think that QTextCursor is nearest…
zeljko wrote 5 lines
There's implementation of TCaret for qt2 in QWindows unit of JVCL (CLX part), and I think that it's maded by one pixmap (used for caret only) + timer.It's written by Andreas Hausladen some years ago.

Ok, I've took his implementation and tried it with our widgetset. First of all we have no BitBlt function in qt bindings, so I replaced it with QPainter stuff. But also all painting should be done in PaintEvent which is very difficult.

As result I have attached here patch. Yes, Andreas code is rather rewritten, but anyway it was his code and to include it into qt widgetset I should ask him about LGPL second I dont know whether this solution is acceptable. Caret works not so stable as in windows or in gtk (yes it do redraw by timer, but sometimes it happens faster and sometimes slower). Maybe some of you can improve code a bit?

Felipe, what do you think? Can we include it into svn after solving at least license question.

Best regards,
Paul Ishenin.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed... Name: qt_caret_1.patch
URL: <http://lists.lazarus.freepascal.org/pipermail/qt/attachments/20070711/4b75d1ec/attachment.ksh>

Felipe Monteiro de Carvalho
to Paul Ishenin
Paul Ishenin wrote
Felipe, what do you think? Can we include it into svn after solving at least license question.

Sure

Felipe Monteiro de Carvalho
Paul Ishenin
to Den Jean: look at shapedclock example for timer based painting (timer causes paint event)
Den Jean wrote 7 lines
On Tuesday 10 July 2007 05:29:33 pm ????? ?????? wrote: >> definitelly, it must be painted inside paint event. >> > That should be reason. look at shapedclock example for timer based painting (timer causes paint event)

I also found this article:
http://lists.trolltech.com/qt-interest/1997-11/thread00093-0.html

So maybe it is possible to draw outside paintEvent?

Best regards,
Paul Ishenin.

zeljko
to Paul Ishenin
Paul Ishenin wrote 13 lines
Den Jean wrote: > On Tuesday 10 July 2007 05:29:33 pm ????? ?????? wrote: >>> definitelly, it must be painted inside paint event. >> >> That should be reason. > > look at shapedclock example for timer based painting (timer causes paint > event) I also found this article: http://lists.trolltech.com/qt-interest/1997-11/thread00093-0.html So maybe it is possible to draw outside paintEvent?

Yes but not as mentioned in article (it was ok for Qt1). Maybe this should help:
QWidget_setAttribute(MyWidget, QtWA_PaintOutsidePaintEvent)

zeljko

Felipe Monteiro de Carvalho
to zeljko
zeljko wrote
Yes but not as mentioned in article (it was ok for Qt1). Maybe this should help: QWidget_setAttribute(MyWidget, QtWA_PaintOutsidePaintEvent)

I think we shouldn't paint outside the paint event, unless the usual way it too much work.

Felipe Monteiro de Carvalho
zeljko
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 7 lines
On 7/11/07, zeljko wrote: > Yes but not as mentioned in article (it was ok for Qt1). > Maybe this should help: > QWidget_setAttribute(MyWidget, QtWA_PaintOutsidePaintEvent) I think we shouldn't paint outside the paint event, unless the usual way it too much work.

I'm against it too, because this solution is not a long way, it will be out of Qt 5, so we'll have problems, but if it can fix the problem until better solution comes let it be.
If Paul uses this attribute ,it will be good if we put it onto Wiki (so nobody should forget about it ;) ).

zeljko

Павел Ишенин
to zeljko
zeljko wrote 18 lines
On Wednesday 11 July 2007 13:17, Felipe Monteiro de Carvalho wrote: > On 7/11/07, zeljko wrote: > >> Yes but not as mentioned in article (it was ok for Qt1). >> Maybe this should help: >> QWidget_setAttribute(MyWidget, QtWA_PaintOutsidePaintEvent) >> > I think we shouldn't paint outside the paint event, unless the usual > way it too much work. > I'm against it too, because this solution is not a long way, it will be out of Qt 5, so we'll have problems, but if it can fix the problem until better solution comes let it be. If Paul uses this attribute ,it will be good if we put it onto Wiki (so nobody should forget about it ;) ).

No boys, forget about it. In note to that attribute written that it is not supported under Windows, OS X. So no way except paintEvent.

Best regards,
Paul Ishenin.