PDA

View Full Version : Qt simultaneous text selection across multiple QPlainTextEdits



shootin4aces
21st October 2015, 18:07
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

anda_skoa
24th October 2015, 17:28
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.


QTextCursor c = textEdit->textCursor();
c.setPosition(startPos);
c.setPosition(endPos, QTextCursor::KeepAnchor);
textEdit->setTextCursor(c);

Cheers,
_