Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Customizing QTextCursor
Forum Updated to NodeBB v4.3 + New Features

Customizing QTextCursor

Scheduled Pinned Locked Moved General and Desktop
11 Posts 4 Posters 4.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    manuelsch
    wrote on last edited by
    #1

    Hi,

    I'd like to implement my own QTextCursor class to reimplement deleteChar() and deletePreviousChar().
    Can anybody tell me how to do this?
    if I do it like this:
    @MyTextCursorClass myCursor(textEdit->textCursor());
    textEdit->setTextCursor(myCursor);@
    I run into a segmentation fault.
    EDIT:
    I run into a segmentation fault if I declare my deleteChar() and deletePreviousChar() as virtual.
    Otherwise my deleteChar() and deletePreviousChar() are not called at all...

    Thanks!

    Manuel

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      QTextCursor contains no virtual methods and thus is not meant to be subclassed.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • M Offline
        M Offline
        manuelsch
        wrote on last edited by
        #3

        Thanks, but how to I reimplement the char deletion event then?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          [quote author="manuelsch" date="1297978558"]Thanks, but how to I reimplement the char deletion event then?[/quote]

          Sorry, I have no idea :-/

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • D Offline
            D Offline
            diegosarmentero
            wrote on last edited by
            #5

            Maybe you can do:
            textCursor.installEventFilter(myObjectj);

            And catch the events related to KeyPress to forward them to your own methods and then return from eventFilter(QObject, QEvent): true or false, depending in what you need...

            Diego Sarmentero
            Blog: http://diegosarmentero.com.ar
            Twitter: http://twitter.com/diegosarmentero

            1 Reply Last reply
            0
            • D Offline
              D Offline
              diegosarmentero
              wrote on last edited by
              #6

              Sorry, my bad, qtextcursor doesn't inherit from qobject...
              But you can apply the behavior that i mention before to the text widget containing the qtextcursor.

              Diego Sarmentero
              Blog: http://diegosarmentero.com.ar
              Twitter: http://twitter.com/diegosarmentero

              1 Reply Last reply
              0
              • M Offline
                M Offline
                MarekR22
                wrote on last edited by
                #7

                What is your initial problem. I'm pretty sure that you are trying do something different and assumed that changing behavior of QTextCursor is a proper solution - but it isn't.
                I suspect that you are trying to implement something like deleting two chars in some spatial case or prevent of delete char (it would be bater if you explain your real problem).

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  manuelsch
                  wrote on last edited by
                  #8

                  Ok, I want to insert building blocks of text into my QTextEdit document.
                  These building blocks consist of several words (like -MS Word's- OpenOffice Writer's form letters).
                  So building blocks should be removed as a whole (not just a one or a few letters of it).

                  And I think this could become pretty hard, because one also has to deal with the deletion of selected text fragments...

                  Any ideas how to handle that?

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    diegosarmentero
                    wrote on last edited by
                    #9

                    I think you can implement that in the QTextEdit, and insert some QTextBlock containing QTextBlockUserData to identify that blocks you mention.

                    Diego Sarmentero
                    Blog: http://diegosarmentero.com.ar
                    Twitter: http://twitter.com/diegosarmentero

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      MarekR22
                      wrote on last edited by
                      #10

                      Problem is quite harsh, somewhere in the past I had similar (more complicated) problem and final result wasn't perfect.
                      listen to the signals "QTextDocument::contentsChange":http://doc.trolltech.com/latest/qtextdocument.html#contentsChange and "QTextDocument::contentsChanged":http://doc.trolltech.com/latest/qtextdocument.html#contentsChanged.
                      On first signal you will store where change has happened on second signal you will use those data to push changes forward (deleting whole block). You can't do it in contentsChange(int,int,int) signal because it will cause a crush.

                      Try also experimenting with QTextObject it might help (I never use it but it looks promising).

                      Some kind of solution can be a "QTextObjectInterface":http://doc.trolltech.com/lates/qtextobjectinterface.html. In this case you provide whole object which will paint those grouped words.
                      This solution requires larger effort, but it will work for sure.

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        manuelsch
                        wrote on last edited by
                        #11

                        Yes, QTextObjectInterface is great!

                        I'm only wondering how serialization is possible: It's using QChar::ObjectReplacementCharacter which does not seem to be written to the database using QDataWidgetMapper.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved