Results 1 to 3 of 3

Thread: QTextEdit on a QGraphicsWidget

  1. #1
    Join Date
    Oct 2009
    Posts
    70

    Default QTextEdit on a QGraphicsWidget

    Hi...

    I've get the example on documentation to put a QTextEdit on a QGraphicsWidget in a QGraphicsScene.

    This is the code:

    Qt Code:
    1. textItem=new QTextEdit;
    2. textItem->setReadOnly(true);
    3. textItem->setFont(myFont);
    4. textItem->setTextColor(Qt::black);
    5. textItem->setTextBackgroundColor(Qt::lightGray);
    6. textItem->setLineWrapMode(QTextEdit::NoWrap);
    7. QGraphicsWidget *textEdit = addWidget(textItem);
    8. textEdit->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum,QSizePolicy::DefaultType);
    9. QGraphicsGridLayout *layout = new QGraphicsGridLayout;
    10. layout->addItem(textEdit,0,0);
    11. layout->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum,QSizePolicy::DefaultType);
    12. textWidget = new QGraphicsWidget;
    13. textWidget->setLayout(layout);
    14. textWidget->setZValue(10);
    15. textWidget->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum,QSizePolicy::DefaultType);
    16. addItem(textWidget);
    To copy to clipboard, switch view to plain text mode 

    where textEdit is a QTextEdit* and textWidget is a QTextWidget*.

    After I set the text on the textItem with setPlainText(QString).

    It works correctly but the problem is that when I show on the scene (the class where this method runs) the widget is larger then the QTextEdit, as shown in the picture.



    How can I, in the correct way, make the QGraphicsWidget with the same size of the QTextEdit?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: QTextEdit on a QGraphicsWidget

    I think this is a feature of QTextEdit to have some margin around the text. You can try some properties of QTextEdit in QtDesigner to see whether you can make this margin disappear.
    It's nice to be important but it's more important to be nice.

  3. #3
    Join Date
    Oct 2009
    Posts
    70

    Default Re: QTextEdit on a QGraphicsWidget

    I can't obtain my goals with QTextEdit...

    Adding this code:

    Qt Code:
    1. QFontMetrics fontMetrics(myFont);
    2. textItem->setFixedHeight(fontMetrics.height() + textItem->frameWidth() * 2);
    To copy to clipboard, switch view to plain text mode 

    I obtain:



    But I want that the width has the lenght of the QTextItem and which I can change the background color of the QGraphicsWidget...

    Is it possible to make it?!

    Thanks

Similar Threads

  1. QTextEdit Performance handling large paragraphs
    By netuno in forum Qt Programming
    Replies: 14
    Last Post: 1st September 2010, 23:58
  2. Drawing on QTextEdit
    By jgrauman in forum Qt Programming
    Replies: 3
    Last Post: 7th February 2009, 10:40
  3. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 13:05
  4. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 07:03
  5. Painting to QTextEdit
    By gesslar in forum Qt Programming
    Replies: 8
    Last Post: 18th February 2006, 19:40

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.