Results 1 to 10 of 10

Thread: multiple cursor selection

  1. #1
    Join Date
    Dec 2014
    Posts
    29
    Qt products
    Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows
    Thanks
    12

    Default multiple cursor selection

    Hello. How can I achieve multiple cursor selection, like here :

    http://i.imgur.com/PF6sX2v.png

    so I can rewrite everything that is found.

    So far I got this:

    http://i.imgur.com/wY66D5l.png ( can only rewrite last word )

    I'm using plainTextEdit widget.

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

    Default Re: multiple cursor selection

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2014
    Posts
    29
    Qt products
    Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows
    Thanks
    12

    Default Re: multiple cursor selection

    Here is code I use:


    Qt Code:
    1. word = self.lineEdit.text()
    2.  
    3. extraSelections = []
    4.  
    5. self.plainTextEdit.moveCursor(QtGui.QTextCursor.Start)
    6. while(self.plainTextEdit.find(word,QtGui.QTextDocument.FindWholeWords)):
    7. '''
    8. selection = QtWidgets.QTextEdit.ExtraSelection()
    9. selection.format.setProperty(QtGui.QTextFormat.FullWidthSelection, True)
    10. selection.cursor = self.plainTextEdit.textCursor()
    11. selection.cursor.clearSelection()
    12. extraSelections.append(selection)
    13. '''
    14. cursor = self.plainTextEdit.textCursor()
    15. cursor.select(QtGui.QTextCursor.WordUnderCursor)
    16. currentWord = QtWidgets.QTextEdit.ExtraSelection()
    17. Color = QtGui.QColor(191, 191, 191, 189)
    18. currentWord.format.setBackground(Color)
    19. currentWord.cursor = cursor
    20. extraSelections.append(currentWord)
    21.  
    22. self.plainTextEdit.setExtraSelections(extraSelections)
    23. self.plainTextEdit.setFocus()
    To copy to clipboard, switch view to plain text mode 
    What am I doing wrong?
    Last edited by vuletic; 19th March 2015 at 22:28.

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

    Default Re: multiple cursor selection

    What is the effect you are getting? How many items does extraSelections have before line #22? Is the cursor for each of the selections set properly?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Dec 2014
    Posts
    29
    Qt products
    Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows
    Thanks
    12

    Default Re: multiple cursor selection

    You can see on second picture what effect I'm getting, if I'm reading this right for(test example) I have

    [<PyQt5.QtWidgets.ExtraSelection object at 0x7f25924b1dd8>, <PyQt5.QtWidgets.ExtraSelection object at 0x7f25924b1c88>, <PyQt5.QtWidgets.ExtraSelection object at 0x7f25924b1eb8>]

    3 items in extraSelections
    Last edited by vuletic; 19th March 2015 at 23:45.

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

    Default Re: multiple cursor selection

    That would probably mean your find() call is incorrect. Maybe you should use QTextDocument::find() instead?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Dec 2014
    Posts
    29
    Qt products
    Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows
    Thanks
    12

    Default Re: multiple cursor selection

    No matter what I try every word is painted correctly, but only last word found is selected.
    Last edited by vuletic; 20th March 2015 at 00:50.

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

    Default Re: multiple cursor selection

    That's because "extra selections" are not real selections. The logic of your program should update all cursors at the same time while you are performing the edit.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Dec 2014
    Posts
    29
    Qt products
    Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows
    Thanks
    12

    Default Re: multiple cursor selection

    Since english is not my native language, maybe I didn't explain it right, but if you look at these two videos:

    this is what I want:
    https://www.youtube.com/watch?v=Ux3_...ature=youtu.be

    and this is what I have at this moment:

    https://www.youtube.com/watch?v=NouO...ature=youtu.be

    the logic of your program should update all cursors at the same time while you are performing the edit.
    that's what I wish to achieve, but I don't know how.

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

    Default Re: multiple cursor selection

    QTextCursor API can be used to edit the document. So if you want to enter "foo" in 10 places, you need to have cursors set to each of the place and use its API to insert "foo" through each cursor.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 0
    Last Post: 5th August 2014, 12:37
  2. Multiple selection ??
    By marc2050 in forum Newbie
    Replies: 1
    Last Post: 9th May 2011, 02:10
  3. QGraphicsScene and multiple selection
    By Bill in forum Newbie
    Replies: 1
    Last Post: 4th August 2009, 15:19
  4. QTableWidget Sorting Multiple Selection
    By rhiacasta in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2006, 21:05
  5. Multiple selection in QTextEdit
    By munna in forum Qt Programming
    Replies: 4
    Last Post: 1st July 2006, 07:58

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
  •  
Qt is a trademark of The Qt Company.