PDA

View Full Version : a Readonly Highlighted TextBlock in QTextEdit?



vertusd
21st July 2010, 13:35
Hi all, i decided to make a texteditor which can edit special format textfile(with tags like (Color:red)Text(Type:4) in it),

It's easy to Highlight Text in a Tag pair with QSyntaxHighlighter, but ,I WANT TO HIDE THE TAGS ,AND MAKE the text in a Tag pair Non-editable

So ,how can i make a Text block Non-editable , while other blocks editable?


Thx. & Sry for my english

borisbn
21st July 2010, 15:58
1. if these tags are not editable, then how can user to add them ?
2. you can parse input file, remove these tags, and make a formatted textblocks instead of them. when you will save a file you should surround formatted textblocks with these tags

vertusd
21st July 2010, 16:45
1. if these tags are not editable, then how can user to add them ?
2. you can parse input file, remove these tags, and make a formatted textblocks instead of them. when you will save a file you should surround formatted textblocks with these tags

Thx for your Reply:

1.The reason making the Tags and Text in them non-editable is to prevent users editing them by mistake, The tool is wrote for translation purpose, and the source texts are generated by a program;
2.The biggest problem is making a selected textblock non-editable, i can leave all tags visiable;

Lykurg
21st July 2010, 16:50
To 2: Yes you can. E.g. for all non editable blocks use QTextBlock::setUserState() and give them 666. Then reimp keypress event or install an event filter and check if the cursor is in a block where the user value is 666. If so, don't propagate the event. That's all.