Results 1 to 3 of 3

Thread: Edit QGraphicsTextItem when click on it

  1. #1
    Join Date
    Jun 2014
    Qt products

    Question Edit QGraphicsTextItem when click on it


    I can't edit a QGraphicsTextItem. Only the tab key work, other keys don't work.

    So, i create my scene here:

    Qt Code:
    1. uml::uml(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. ui.setupUi(this);
    5. m_pScene = new QGraphicsScene;
    6. ui.graphicsView->setScene(m_pScene);
    7. }
    To copy to clipboard, switch view to plain text mode 

    And my QGraphicsTextItem:
    Qt Code:
    1. QTextEdit* text= widget->findChild<QTextEdit*>("text");
    2. QString strText = methodes->toPlainText();
    3. QGraphicsTextItem* classeText = new QGraphicsTextItem(strText );
    4. classeText ->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsMovable);
    5. classeText ->setTextInteractionFlags(Qt::TextEditorInteraction);
    To copy to clipboard, switch view to plain text mode 

    With this thing, don't work. How to do for change texte of one of this ?

  2. #2
    Join Date
    Sep 2021
    Qt products

    Default Re: Edit QGraphicsTextItem when click on it

    Was a solution to this found?

    I have the same issue.

  3. #3
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 831 Times in 818 Posts
    Qt products
    Windows Android

    Default Re: Edit QGraphicsTextItem when click on it

    QGraphicsTextItem uses a QTextDocument to store its content. You can retrieve the document using QGraphicsTextItem::document() and set it using QGraphicsTextItem::setDocument() and can change the contents of that document if your graphics item contains more than just plain text. You can call QGraphicsTextItem::setPlainText() if you just have a string to display.

    If you want to interactively edit the content of the QGraphicsTextItem, you need to set the Qt::TextInteractionFlags to Qt::TextEditable using QGraphicsTextItem::setTextInteractionFlags(). The default setting is Qt::NoTextInteraction, which means the item is display-only.

    I assume when you set the flag to editable, double-clicking will change the item into a QTextEdit for editing. However, you do not have access to this, only to the QTextDocument. If you need to know what the user has changed the text to, then you can connect to the document's signals.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 5
    Last Post: 5th June 2013, 08:02
  2. Replies: 2
    Last Post: 23rd December 2010, 09:53
  3. Edit Text of a QPushButton with mouse right click
    By theria05 in forum Qt Programming
    Replies: 6
    Last Post: 8th December 2010, 19:49
  4. Replies: 51
    Last Post: 26th November 2010, 14:24
  5. Word at mouse click position in QGraphicsTextItem
    By pherthyl in forum Qt Programming
    Replies: 2
    Last Post: 3rd November 2008, 05:56

Tags for this Thread


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.