Results 1 to 13 of 13

Thread: QGraphicTextItem and outline

  1. #1
    Join Date
    Aug 2009
    Posts
    81
    Platforms
    MacOS X Windows

    Default QGraphicTextItem and outline

    Is it possible to have an outline text on a QGraphicTextItem? I cannot find anyway to achieve that!

    thank you for your help

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QGraphicTextItem and outline

    You need to set a pen and a brush.

    If you add a text document, you can create your own layout using QTextCharFormat etc...

    Edit: it is not nice to ask the same question on multiple forums. It shows a lack of respect and trust.
    Last edited by tbscope; 17th October 2010 at 06:30.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QGraphicTextItem and outline


  4. #4
    Join Date
    Aug 2009
    Posts
    81
    Platforms
    MacOS X Windows

    Default Re: QGraphicTextItem and outline

    Hello, thank you for your hints but i do not see how the painterpath can let me have rich text as it works within QGraphicsTextItem... where do i collect it...can you explain me more

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QGraphicTextItem and outline

    Quote Originally Posted by eric_vi View Post
    Is it possible to have an outline text on a QGraphicTextItem?
    Quote Originally Posted by eric_vi View Post
    Hello, thank you for your hints but i do not see how the painterpath can let me have rich text as it works within QGraphicsTextItem...
    Where did you mentioned rich text in your question?

  6. #6
    Join Date
    Aug 2009
    Posts
    81
    Platforms
    MacOS X Windows

    Default Re: QGraphicTextItem and outline

    well qgraphictextitem is as opposed to qgraphicsimpletextitem and let me reedit the text, is it not?

  7. #7
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QGraphicTextItem and outline

    As I already said:
    Use a QTextDocument. Iterate over the textblocks, for each cursor position, get the text format, set an outline pen in that format.

    It's already there for you to use: http://doc.qt.nokia.com/4.7/qtextcha...setTextOutline

  8. #8
    Join Date
    Aug 2009
    Posts
    81
    Platforms
    MacOS X Windows

    Default Re: QGraphicTextItem and outline

    hi, thank you very much, it is clearer now... i do apologize i don't have your expertise.

    Should i put this method reimplementing the paint of my QGraphicsTextItem

  9. #9
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QGraphicTextItem and outline

    You do not need to reimplement anything.

    Instead of using a plain or rich text in the graphics text item, use a text document. Then go down a level to access the text blocks and set the character format for those blocks.

    http://doc.qt.nokia.com/4.7/qgraphic...ml#setDocument
    http://doc.qt.nokia.com/4.7/qtextdocument.html
    http://doc.qt.nokia.com/4.7/qtextblock.html

    Edit:
    If you use a text cursor, you can directly insert text with a certain format.
    http://doc.qt.nokia.com/4.7/qtextcursor.html#insertText

    this example uses text objects, but it can be usefull for your situation too:
    http://doc.qt.nokia.com/4.7/richtext-textobject.html

  10. #10
    Join Date
    Aug 2009
    Posts
    81
    Platforms
    MacOS X Windows

    Default Re: QGraphicTextItem and outline

    okie

    the user is the one that does edit the text of this qgraphicstextitem... i am not inserting any programmatically like in the richtext object example


    if i try to insert the following as i am initializing my own implementation of qgraphicstextitem


    Qt Code:
    1. QPen outlinePen = QPen (QColor(255, 0, 0), 1, Qt::SolidLine);
    2.  
    3. format.setTextOutline ( outlinePen );
    4.  
    5. QTextCursor cursor;
    6. cursor.setCharFormat ( format );
    7. setTextCursor(cursor);
    To copy to clipboard, switch view to plain text mode 

    i got a cursor but i cannot edit (enter any text anymore) that is where i am stuck. If i remove those lines i can edit normally (but without outlined text!)

  11. #11
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QGraphicTextItem and outline

    Quote Originally Posted by eric_vi View Post
    i got a cursor but i cannot edit (enter any text anymore) that is where i am stuck. If i remove those lines i can edit normally (but without outlined text!)
    Well, I made myself a test program and it works perfectly here, with the outline or any styling I want. Including the editing.

    You might want to provide a little toolbar with editing options too if you want.

    Edit: here's part of the code for inspiration:

    Qt Code:
    1. ui->setupUi(this);
    2.  
    3. scene = new QGraphicsScene(ui->graphicsView);
    4. ui->graphicsView->setScene(scene);
    5.  
    6. document = new QTextDocument;
    7.  
    8. QTextCharFormat charFormat;
    9. charFormat.setFont(QFont("times", 24));
    10.  
    11. QPen outlinePen = QPen (QColor(255, 0, 0), 1, Qt::SolidLine);
    12. charFormat.setTextOutline(outlinePen);
    13.  
    14. QTextCursor cursor = QTextCursor(document);
    15. cursor.insertText("Test", charFormat);
    16.  
    17. textItem = new QGraphicsTextItem();
    18. textItem->setDocument(document);
    19. textItem->setTextInteractionFlags(Qt::TextEditable);
    20. scene->addItem(textItem);
    To copy to clipboard, switch view to plain text mode 
    Last edited by tbscope; 17th October 2010 at 20:16.

  12. #12
    Join Date
    Aug 2009
    Posts
    81
    Platforms
    MacOS X Windows

    Default Re: QGraphicTextItem and outline

    well having a toolbar is the plan but i have to pass the first hurdle.. so you mean just by placing

    Qt Code:
    1. QPen outlinePen = QPen (QColor(255, 0, 0), 1, Qt::SolidLine);
    2.  
    3. format.setTextOutline ( outlinePen );
    4.  
    5. QTextCursor cursor;
    6. cursor.setCharFormat ( format );
    7. setTextCursor(cursor);
    To copy to clipboard, switch view to plain text mode 

    on a qgraphicstextitem without anything extra this edits fine? do you do any setup to the QTextDocument attached to the qgraphicstextitem ?

  13. #13
    Join Date
    Aug 2009
    Posts
    81
    Platforms
    MacOS X Windows

    Default Re: QGraphicTextItem and outline

    was missing document()

    ----> QTextCursor cursor = QTextCursor(document());

    it works well .... thank you very much for your excellent help

    by the way ... it is not that i don't trust a forum if i post a question on different ones... but sometime you don't get answer on some (and i can understand that too). It is just that some issues are sometime blocking the progression of your work and you want to figure a solution as fast as possible.


    Thanks again

Similar Threads

  1. QPushButton: Outline white text in black on transparent background
    By Tito in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 20th July 2011, 07:16
  2. How to remove 3D frame and outline in QToolButton?
    By Kevin Hoang in forum Qt Programming
    Replies: 9
    Last Post: 9th March 2010, 14:31
  3. Checking for intersect of QPainterPath OUTLINE?
    By SonOfGuest in forum Qt Programming
    Replies: 1
    Last Post: 12th May 2009, 00:30
  4. Line Outline?
    By jon-ecm in forum Qt Programming
    Replies: 0
    Last Post: 23rd April 2009, 00:46
  5. Frame around a QGraphicTextItem
    By Orphelic in forum Qt Programming
    Replies: 4
    Last Post: 21st July 2008, 14:28

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.