Results 1 to 2 of 2

Thread: Qt simultaneous text selection across multiple QPlainTextEdits

  1. #1
    Join Date
    Oct 2015
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Question Qt simultaneous text selection across multiple QPlainTextEdits

    Thanks in advance for any help or ideas that lead me to success!

    I am currently writing a simple Hex Viewer application in Qt 5+. I have almost everything together but I am really struggling with one last issue I could use some assistance on.

    As It stands I have a main window with 3 subclassed QPlainTextEdit widgets (to handle simultaneous scrolling of all 3) displayed in a row to the user. The first column is simply a line address indexing, second is the Hex view, third is the Ascii translation where Every character that is not in extended ascii is replaced with a '.' (like most hex viewers). Everything I have is working as expected but I have no idea where to go with the last feature I need.

    When the user highlights Hex in the middle text edit, I want the Ascii that relates to it to be highlighted as well in the right text edit (and vice versa). I have no clear idea how to go about doing this last task.

    Could someone please point me in the right direction and help me to figure this aspect out? One additional issue is I need to account for space in the hex view as it displays each line as "XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX" ... im sure that aspect is trivial after the first question is answered.

    thanks for the help

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt simultaneous text selection across multiple QPlainTextEdits

    Quote Originally Posted by shootin4aces View Post
    Could someone please point me in the right direction and help me to figure this aspect out?
    I am sure you have some internal data structure that allows you to map from one view's positions to the other view's position, i.e. you can determine where the selection would need to start and where to end.

    Applying the selection is done through the QTextCursor interface.
    Qt Code:
    1. QTextCursor c = textEdit->textCursor();
    2. c.setPosition(startPos);
    3. c.setPosition(endPos, QTextCursor::KeepAnchor);
    4. textEdit->setTextCursor(c);
    To copy to clipboard, switch view to plain text mode 
    Cheers,
    _

Similar Threads

  1. QNetworkAccessManager and multiple simultaneous requests
    By Angelo Cruz in forum Qt Programming
    Replies: 4
    Last Post: 2nd July 2015, 22:09
  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. QTextDocuments and QPlainTextEdits
    By JordyD in forum Qt Programming
    Replies: 10
    Last Post: 8th July 2009, 20:38
  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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.