Results 1 to 7 of 7

Thread: QGraphicsTextItem doesn't show up

  1. #1
    Join Date
    Apr 2010
    Posts
    11
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsTextItem doesn't show up

    I have a QGraphicsScene to show some data points. Each data point is an QGraphicsItem object and added to the scene with QGraphicsScene::addItem() function. All data points are shown OK.

    Then I want to add a text to the same scene. I use QGraphicsTextItem and the code looks something like:

    QGraphicsTextItem *text = new QGraphicsTextItem("Data");
    myScene->addItem(text);

    But the text does not show up! Do I miss some settings for QGraphicsTextItem here? I checked some code examples on the forum and it looked as simple as above. Why mine does not work?

    Also, if I want to put the text on a location on the scene, should I use QQGraphicsItem::setPos(x,y), where x and y are in scene coodinates?

    Thanks a lot for any help!

  2. #2
    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: QGraphicsTextItem doesn't show up

    Your code is fine, also use setPos() for arranging your text item. I can't think of any reason, why your text is not shown, but I guess the "error" in somewhere in your surrounding code. So please check in a simple example, if you can insert texts to a scene. If so, search your other code for errors.

  3. #3
    Join Date
    Apr 2010
    Posts
    11
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsTextItem doesn't show up

    I ran a standalone simple example with QGraphicsTextItem and it works fine. So I believe there is something in my application code that caused the problem.

    When I added other QGraphicsItem's to the my scene (such as QGraphicsLineItem), all worked OK. But only QGraphicsTextItem does not! Any difference between QGraphicsLineItem and QGraphicsTextItem? I just do not understand why.

  4. #4
    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: QGraphicsTextItem doesn't show up

    No, no difference. Can you show some code?

    Possible issues I can think of:
    • Item is outside the visible area
    • background color and your font color are the same
    • If you use a custom font, it is maybe not found

  5. #5
    Join Date
    Apr 2010
    Posts
    11
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsTextItem doesn't show up

    I did not change any setting for QGraphicsTextItem, just simply create it and add it to the scene like this:

    QGraphicsTextItem *text = new QGraphicsTextItem("Data");
    myScene->addItem(text);

    One thing I can guess is that the text is drawn out of visible area. How do I control the area or the boundary of the text?

  6. #6
    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: QGraphicsTextItem doesn't show up

    after you have added the item call setSceneRect() with QGraphicsScene::itemsBoundingRect(), then you should scroll to each item.

    EDIT: It it is maybe hidden by another item? Try to "play" with the z value of the item.

  7. #7
    Join Date
    Apr 2010
    Posts
    11
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsTextItem doesn't show up

    Thanks, Lykurg. I tried calling QGraphicsScene::itemsBoundingRect() and QGraphicsScene::sceneRect() where there is only an QGraphicsTextItem added to the scene. It turned out that the items bounding rect is much larger than the scene rect. That is why the text item is not shown on the scene.

    I do not know why the default QGraphicsTextItem has such larger bounding rect. How can I make it smaller to fit within the scene rect?

Similar Threads

  1. QCalenderWidget doesn't show the month name and Day name.
    By jthacker in forum Qt Programming
    Replies: 2
    Last Post: 28th April 2010, 20:43
  2. Application running but doesn't show up!!!
    By joandelason in forum Newbie
    Replies: 4
    Last Post: 21st March 2010, 09:37
  3. QGraphicsTextItem: How to show the text cursor?
    By breezeight in forum Qt Programming
    Replies: 1
    Last Post: 17th November 2009, 16:44
  4. Replies: 0
    Last Post: 13th February 2009, 15:17
  5. QSystemTrayIcon doesn't show icon ?
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 25th January 2007, 19:17

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.