PDA

View Full Version : QGraphicsTextItem: handling cursor position change



Angelo Moriconi
29th January 2007, 13:23
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.

In QTextEdit widgets there is a signal very useful 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

wysota
29th January 2007, 15:54
Catch the key event for the item and handle it there, without signals.

Angelo Moriconi
30th January 2007, 10:42
I catch the key press event and the mouse press event and I handle, after calling the respective parent methods, the cursor position.

Now all works fine,

thanks

Angelo