Results 1 to 3 of 3

Thread: QGraphicsTextItem: handling cursor position change

  1. #1
    Join Date
    Jan 2007
    Location
    Rome
    Posts
    30
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Post QGraphicsTextItem: handling cursor position change

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsTextItem: handling cursor position change

    Catch the key event for the item and handle it there, without signals.

  3. #3
    Join Date
    Jan 2007
    Location
    Rome
    Posts
    30
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Smile Re: QGraphicsTextItem: handling cursor position change

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.