Results 1 to 1 of 1

Thread: Multiple selecting problem (PySide)

  1. #1

    Default Multiple selecting problem (PySide)

    I have a problem(or not so much a problem, more like a functionality i really want to implement). I am working with my colleagues on a first year of faculty on an advance Text editor program and we use PySide, and i'm working now on a find function which uses a Knuth-Morris-Pratt algorithm and text selection. The following function i made only selects the last found word which is logical, but i want to select all, or on any way highlight the words i have found. I have searched for so long, and i have found some articles with setExtraSelections but i didn't manage to implement it to work the way i want. Can someone help me with this problem?

    x is a list with indexes of the first letter of the found word.

    self.mdiWidget.currentWidget() is the active QTextEdit widget.

    Qt Code:
    1. def find(self):
    2. input = QInputDialog.getText(self.mdiWidget.currentWidget(), unicode("Find"), unicode('Unesite Tekst:'))
    3. txt = self.mdiWidget.currentWidget().toPlainText()
    4. x = kmp(txt.encode("UTF-8"), input[0].encode("UTF-8"))
    5. if x == []:
    6. msgBox = QMessageBox()
    7. msgBox.setText("Nothig is found")
    8. msgBox.exec_()
    9. c = self.mdiWidget.currentWidget().textCursor()
    10. for i in x:
    11. c.setPosition(i)
    12. c.setPosition(i+len(input[0]), QTextCursor.KeepAnchor)
    13. self.mdiWidget.currentWidget().setTextCursor(c)
    To copy to clipboard, switch view to plain text mode 

    That was what i have initional done.

    Then i managed to do this, like its done in the video: https://vid.me/2yuT
    The problem now is, i want to clear these extra selections on cursor position or selection change but i don't get it how to do it. Here is the code i edited:

    Qt Code:
    1. def find(self):
    2. input = QInputDialog.getText(self.mdiWidget.currentWidget(), unicode("Find"), unicode('Unesite Tekst:'))
    3. txt = self.mdiWidget.currentWidget().toPlainText()
    4. x = kmp(txt.encode("UTF-8"), input[0].encode("UTF-8"))
    5. if x == []:
    6. msgBox = QMessageBox()
    7. msgBox.setText("Nothig is found")
    8. msgBox.exec_()
    9. extraSelections = []
    10. c = self.mdiWidget.currentWidget().textCursor()
    11. for i in x:
    12. c.setPosition(i)
    13. c.setPosition(i+len(input[0]), QTextCursor.KeepAnchor)
    14. self.mdiWidget.currentWidget().setTextCursor(c)
    15. Color = QColor(191, 191, 191, 189)
    16. currentWord = self.mdiWidget.currentWidget().ExtraSelection()
    17. currentWord.format.setBackground(Color)
    18. currentWord.cursor = c
    19. extraSelections.append(currentWord)
    20. self.mdiWidget.currentWidget().setExtraSelections(extraSelections)
    To copy to clipboard, switch view to plain text mode 

    EDIT: I know this is a C++ forum, but i don't know where to ask.
    Last edited by greenenvy; 23rd May 2015 at 19:40.

Similar Threads

  1. QTableView problem - selecting multiple items
    By junhonguk in forum Qt Programming
    Replies: 2
    Last Post: 18th July 2012, 14:16
  2. Qt Creator Problem selecting the correct mkspec/qmake.conf file
    By weaver4 in forum Qt Tools
    Replies: 1
    Last Post: 2nd December 2010, 13:37
  3. Replies: 0
    Last Post: 12th April 2010, 12:22
  4. problem in selecting base class
    By durgarao in forum Qt Tools
    Replies: 5
    Last Post: 2nd January 2009, 10:13
  5. Replies: 2
    Last Post: 10th March 2006, 18:04

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.