Results 1 to 7 of 7

Thread: Need some help with QGraphicsTextItem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Need some help with QGraphicsTextItem

    Hello again, I want to be able to write text in the QGraphicsscene. I want to be able to do this by clicking button that calls a slot that adds a QGraphicsTextItem in the scene and from there i can start typing. Here is my code below. this is the slot function.
    Qt Code:
    1. void MainWindow::on_font_btn_clicked()
    2. {
    3. text = new TextItem();
    4. text->setParentItem(page_1);
    5. text->setFont(fontCombo->currentFont());
    6. text->setZValue(1000.0);
    7. scene->addItem(text);
    To copy to clipboard, switch view to plain text mode 
    }
    but for some reason this is not working. NB: this text is to be written within the "rect" of the parent item. Am I missing something here?

  2. #2
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Need some help with QGraphicsTextItem

    Does anybody have any idea what the problem could be here?

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

    Default Re: Need some help with QGraphicsTextItem

    What exactly is "not working"?
    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
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Need some help with QGraphicsTextItem

    The ultimate goal is to be able write some text over a QGraphicsItem (i.e. the parent item to the QGraphicstextItem) but that is not happening with the code I posted above. How it is suppose to work is that, I need to be able to able click a button (i.e. the add text button) and then click on a position on scene to place the cursor and then start typing but none of that is happening with the above code. the above code is implemented in a slot function for the add text button.

    Thanking you in advance.

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

    Default Re: Need some help with QGraphicsTextItem

    "none of that"? You mean you are not able to click a button, you are not able to click on the scene or you are not able to start typing? Your code above only adds an item without text to the scene. It does nothing of what you mentioned.
    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
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Need some help with QGraphicsTextItem

    I mean when I click on the button "Add Text" and then click on a position on the scene, I then expect to see a blinking text cursor on that position which will then allow me to start typing the text. That is what I am aiming for. At the moment, when I click on the "Add Text" but and then click on the scene, Nothing happens (i.e. NO TEXT CURSOR IS ADDED TO THE SCENE).

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

    Default Re: Need some help with QGraphicsTextItem

    Why would a text cursor be added to the scene? You are adding an item to the scene but you are not telling the item that you'd like to edit it. QGraphicsItem::setFocus() gives focus to an item.
    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.


Similar Threads

  1. Replies: 51
    Last Post: 26th November 2010, 13:24
  2. QGraphicsTextItem and shadows
    By eric_vi in forum Qt Programming
    Replies: 0
    Last Post: 15th October 2010, 20:59
  3. QGraphicsTextItem in a Widget ,Is it Possible ??
    By salmanmanekia in forum Qt Programming
    Replies: 10
    Last Post: 28th July 2008, 13:45
  4. resizing a qgraphicstextitem
    By dreamer in forum Qt Programming
    Replies: 6
    Last Post: 22nd May 2008, 15:43
  5. QGraphicsTextItem - is it a bug there?
    By Tair in forum Qt Programming
    Replies: 5
    Last Post: 18th October 2006, 08:48

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.