Hi
Is there a way of making some text within a QTextEdit non editable?
I want to insert some text programatically but prevent the user from editing this text.
thanks
Printable View
Hi
Is there a way of making some text within a QTextEdit non editable?
I want to insert some text programatically but prevent the user from editing this text.
thanks
I think you'd need to implement your own QTextObject subclass.
Thanks for the hint
How would I make my QTextObject read only?
You can start by reading the docs, especially the Text Object Example.
Hi
OK, I have read the relevant docs and started to implement my own text object for inserting a string.
I can now get this displayed, but am struggling with how to correctly implement the 'intrinsicSize' method.
inside this method I can obtain the string to be inserted and then i tried to calculate the size required to display it
Code:
qreal pointSize = fmt.fontPointSize(); size.setHeight(pointSize); size.setWidth(pointSize*str.length());
but he size is always 0.
I would appreciate any hint as to how to correctly implement this
Thanks
Hi
Thanks for the help
Inside the 'intrinsicSize' method I retrive the font by -
But this always returns the same thing, I want the font being used in the document at the point that I insert the text.Code:
Why does my code not work?
Thanks
This returns the text format of the whole block. If you want the format for your item, use QTextObject::format() and convert it to the proper type. You can also use QTextCursor::charFormat().
Hi
Within the intrinsicSize method I cannot get on object of type QTextObject or QTextCursor.
returns a null pointer.
QTextCursor belongs to the QTextEdit class which does not seem to be available in this method
Am I missing something?
Graham
QTextCursor doesn't belong to QTextEdit class. You can have as many cursors as you want, have a look at available constructors. And I have no idea what your objectForFormat() call was supposed to do. You are implementing QTextObject subclass so just calling format() will return a QTextFormat which you can then convert to another type using the API available in QTextFormat.
OK now I am confused
You say I am implementing a QTextObject subclass, but I am just following the TextObject example that implements
QTextObjectInterface.
Where should I be creating a QTextObject ?
Thanks
True. However you get a QTextFormat as the argument to intrinsicSize(), haven't you noticed?
I have made some progress with he following implementation
Code:
{ painter->setFont(font); painter->drawText(rect,str); }
Is this the correct way or is there a better way?
Thanks for your help
If it works for you, it is fine with me.
Thanks for your assistance
But I'm not sure that its going to help me!
I need to be able to save the document but when I do so the custom object is not saved
Need some more research
Any hints on this
Thanks
How are you "saving" it?
I tried converting the contents to html and saving that
I also tried saving as an odt document
HTML doesn't allow any "protected text" so there is no way you are going to succeed. ODT writer only allows simple things, so no joy here too.
Is there anything that might work?
You can implement your own writer and your own reader if you need to recreate the text document from a file.