Results 1 to 1 of 1

Thread: How to reimplement sizeHint()?

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

    Question How to reimplement sizeHint()?

    I'm making a subclass of QGraphicsLayoutItem, but can't quite figure out, how to correctly reimplement sizeHint() function. Here's what I got now:

    Qt Code:
    1. QSizeF PLFTextItem::sizeHint (Qt::SizeHint _which, const QSizeF &_constraint) const
    2. {
    3. switch (_which)
    4. {
    5. case Qt::MinimumSize: return m_sizeHint;
    6. case Qt::PreferredSize: return _constraint.expandedTo (m_sizeHint);
    7. }
    8. return QSizeF();
    9. }
    To copy to clipboard, switch view to plain text mode 

    Where m_sizeHint bears the actual size of an object being displayed (in this case, simple text item). Also, the size policy for this item is (QSizePolicy::Preferred, QSizePolicy::Fixed), and stretch, both horizontal and vertical, is 0.

    The problem is, when I put this layout item into, say, a linear layout with a couple of others, horizontally it takes more space than it needs, and also takes it somewhat proportionally to m_sizeHint. What am I doing wrong?

    Here is a screenshot of my QGraphicsScene, to make things clear:
    Layout fail.jpg

    And while we are at it, I wonder if I'm doing the whole thing entirely wrong: subclassing QGraphicsLayoutItem just to handle QGraphicsSimpleTextItem with layouts. It sure seems a little awkward, but QGraphicsLayoutItem::setGraphicsItem() is protected, and you still need to move QGraphicsItem in question when setGeometry is called. Is there any simpler way? But even if there is, I'll be doing some more complex stuff inside another QGraphicsLayoutItem, and I'd probably want to sublcass anyway. So the question still stands.
    Last edited by Septi; 6th July 2010 at 16:46. Reason: Oh, so there are attachments... ))

Similar Threads

  1. ReImplement showPopup for my QComboBOx
    By ber0y in forum Newbie
    Replies: 5
    Last Post: 8th April 2012, 12:42
  2. issues regarding how to reimplement keyPressEvent()
    By Askar in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2009, 14:32
  3. Reimplement ::paintEvent of QLabel
    By Qt Coder in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2009, 12:18
  4. Reimplement of resizeEvent
    By Shawn in forum Qt Programming
    Replies: 20
    Last Post: 27th May 2007, 10:04
  5. Reimplement QSplashScreen::drawContents
    By ucomesdag in forum Qt Programming
    Replies: 12
    Last Post: 24th November 2006, 09:39

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.