Results 1 to 20 of 21

Thread: protect some text in a QTextEdit

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: protect some text in a QTextEdit

    True. However you get a QTextFormat as the argument to intrinsicSize(), haven't you noticed?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: protect some text in a QTextEdit

    I have made some progress with he following implementation
    Qt Code:
    1. QSizeF SvgTextObject::intrinsicSize(QTextDocument * doc, int posInDocument,
    2. const QTextFormat &format)
    3. {
    4. QSize size;
    5.  
    6. QString str = qVariantValue<QString>(format.property(Window::SvgData));
    7.  
    8. QTextCursor cursor(doc);
    9. QTextCharFormat fmt = cursor.charFormat();
    10.  
    11. QFont font = fmt.font();
    12. QFontMetrics fm(font);
    13. QRect rect = fm.boundingRect(str);
    14.  
    15. size.setHeight(rect.height());
    16. size.setWidth(rect.width());
    17. return QSizeF(size);
    18. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void SvgTextObject::drawObject(QPainter *painter, const QRectF &rect,
    2. QTextDocument * /*doc*/, int /*posInDocument*/,
    3. const QTextFormat &format)
    4. {
    5. const QString str = qVariantValue<QString>(format.property(Window::SvgData));
    6. QTextCursor cursor(doc);
    7. QTextCharFormat fmt = cursor.charFormat();
    8.  
    9. QFont font = fmt.font();
    10. painter->setFont(font);
    11. painter->drawText(rect,str);
    12. }
    To copy to clipboard, switch view to plain text mode 

    Is this the correct way or is there a better way?

    Thanks for your help

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: protect some text in a QTextEdit

    If it works for you, it is fine with me.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: protect some text in a QTextEdit

    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

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: protect some text in a QTextEdit

    How are you "saving" it?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: protect some text in a QTextEdit

    I tried converting the contents to html and saving that
    I also tried saving as an odt document

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: protect some text in a QTextEdit

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: protect some text in a QTextEdit

    Is there anything that might work?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: protect some text in a QTextEdit

    You can implement your own writer and your own reader if you need to recreate the text document from a file.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. The following user says thank you to wysota for this useful post:

    GrahamLabdon (11th October 2011)

  11. #10
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: protect some text in a QTextEdit

    I thought that's what you'd say!
    Thanks for all your help

Similar Threads

  1. Protect PDF File
    By wirasto in forum Newbie
    Replies: 2
    Last Post: 25th August 2009, 10:19
  2. Replies: 1
    Last Post: 4th December 2008, 06:55
  3. Protect QSqlQueryModel in two threads
    By john_crichton in forum Qt Programming
    Replies: 1
    Last Post: 2nd May 2008, 17:00
  4. QTextEdit + paste rich text as plain text only
    By Yong in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 16:45
  5. Problem on set QGraphicsTextItem write protect.
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2007, 20:53

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
  •  
Qt is a trademark of The Qt Company.