Results 1 to 15 of 15

Thread: bad sceneRect with scaled text

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2008
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question bad sceneRect with scaled text

    In a subclassed QGraphicsTextItem, I'm drawing some text and scaling it down in size to fit into a small area in the Scene. (I found that I have to scale, because the needed size is smaller than what I can get by using a small point size with setFont().) I adjust the scale as follows, depending on the maxHeight that I want to see in the scene.

    Qt Code:
    1. setFont(QFont("Times", 40));
    2. setDefaultTextColor(QColor(Qt::white));
    3. QFontMetricsF fm(font());
    4. qreal s = maxHeight / fm.height();
    5. scale(s, -s);
    6. translate(-(fm.width(net)/2), -(fm.height()/2));
    7. setPlainText(net);
    To copy to clipboard, switch view to plain text mode 
    The text is displayed properly. However, when I try zooming to fit, using the code below, the sceneRect is much, much larger than what I expect. So, the zoom doesn't work right. Without the text everything works fine. When I add the text the zoomed view shows everything crammed into a tiny area in a corner with empty space covering the rest of the view. It's almost as if the sceneRect() is being computed using unscaled, rather than scaled text.

    Qt Code:
    1. pcbDoc->getScene()->setSceneRect(QRectF());
    2. view->fitInView(pcbDoc->getScene()->sceneRect(), Qt::KeepAspectRatio);
    To copy to clipboard, switch view to plain text mode 
    Obviously I'm doing something wrong, but I need a hint.
    Thanks!
    Last edited by jpn; 8th July 2008 at 07:46. Reason: changed [indent] to [code] tags

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 14:36
  3. Match the text beetween two string
    By dreamer in forum Qt Programming
    Replies: 4
    Last Post: 20th May 2008, 14:48
  4. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 12:05
  5. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 15:30

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
  •  
Qt is a trademark of The Qt Company.