Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, January 2007
QGraphicsTextItem: handling cursor position change


Message 1 in thread

Hi !
I am developing a custom QGraphicsTextItem with simple text editor functions
like bold,italic, underline font support.
I create a standard toolbar that modify (and merge if necessary) the
QTextCharFormat of the document returned from the QGraphicsTextItem and I
want to sync the checked buttons (bold, italic, underline) with the current
cursor position (like in the Text Edit example)

In QTextEdit widgets there is a useful signal to accomplish this task
(cursorPositionChanged) that is emitted whenever the position of the cursor
changed.

Using a QGraphicsTextItem I have access only to a QTextDocument that have a
similar signal (with the same name: cursorPositionChanged) that is emitted
whenever the position of a cursor changed *due to an editing operation*.

In the documentation is written: "If you need a signal when the cursor is
moved with the arrow keys you can use the cursorPositionChanged() signal in
QTextEdit."

In this particular case I cannot use this kind of signal, there is another
way to perform the same task in a QGraphicsTextItem (check the current text
char format) ?

Thanks in advance,

Angelo

Message 2 in thread

Angelo Moriconi wrote:
> In this particular case I cannot use this kind of signal, there is another
> way to perform the same task in a QGraphicsTextItem (check the current
> text char format) ?

No, I'm afraid not. Your best bet is to subclass QGraphicsTextItem, and
reimplement keyPressEvent and keyReleaseEvent.

Andreas

-- 
 [ signature omitted ] 

Message 3 in thread

>
> No, I'm afraid not. Your best bet is to subclass QGraphicsTextItem, and
> reimplement keyPressEvent and keyReleaseEvent.
>
>
Thanks,
I reimplement only the keyPressEvent and the mousePressEvent and with a new
signal I
can manage the correct cursor position.

Angelo