Results 1 to 10 of 10

Thread: How to fixed the size of the QGraphicsScene.?

  1. #1
    Join Date
    Apr 2011
    Posts
    39
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default How to fixed the size of the QGraphicsScene.?

    Hi,

    I am having QGraphicsScene in the QGraphicsView,

    now what happens is when I set any QPixmap to QGraphicsScene then it will change QGraphicsScene to QPixmap size,

    that is not my requirement,
    I want to fixed the size of the QGraphicsScene and then image should be adjusted according to QGraphicsScene's size no matter how big an image was.

    Please kindly provide me the solution,

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to fixed the size of the QGraphicsScene.?

    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Apr 2011
    Posts
    39
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to fixed the size of the QGraphicsScene.?

    I have tried it but that will bound the QGraphicsScene's size to minimum means QGraphicsScene will not shrink less then provided,
    but QGraphicsScene can take any size maximum than that,
    that is not needed in my case,

    hope u understand ....

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to fixed the size of the QGraphicsScene.?

    hope u understand ....
    am... actually I don't... sorry...
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to fixed the size of the QGraphicsScene.?

    You could reimplement
    Qt Code:
    1. QGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect)
    To copy to clipboard, switch view to plain text mode 

    and use the QPainter to draw the QPixmap. Because it looks me to you want the pixmap as background or?

    You could even do something like
    Qt Code:
    1. painter->drawPixmap(0,0, m_backgroundImage.scaled(rect.width(), rect.height(),Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Apr 2011
    Posts
    39
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to fixed the size of the QGraphicsScene.?

    when I am using

    painter->drawPixmap(0,0, m_backgroundImage.scaled(rect.width(), rect.height(),Qt::IgnoreAspectRatio, Qt::SmoothTransformation));

    I am getting the error that painter is not active.
    please guide me

  7. #7
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to fixed the size of the QGraphicsScene.?

    Try calling QPainter::begin() and QPainter::end(). http://doc.qt.nokia.com/latest/qpainter.html#begin

  8. #8
    Join Date
    Apr 2011
    Posts
    39
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to fixed the size of the QGraphicsScene.?

    I am using QPainter::begin() and QPainter::end().
    dude .... !!!!

  9. #9
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to fixed the size of the QGraphicsScene.?

    Then your code is wrong.

  10. #10
    Join Date
    Apr 2011
    Posts
    39
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to fixed the size of the QGraphicsScene.?

    Actually I am using QPainter outside of paintevent().

Similar Threads

  1. Replies: 4
    Last Post: 20th November 2009, 12:25
  2. Fixed size axes
    By wim12 in forum Qwt
    Replies: 4
    Last Post: 15th May 2009, 12:37
  3. Print html on fixed size
    By mamyte03@gmail.com in forum Qt Programming
    Replies: 1
    Last Post: 19th September 2007, 10:33
  4. A fixed size window?
    By adorp in forum Qt Tools
    Replies: 4
    Last Post: 25th July 2007, 18:57
  5. QDockWidget fixed size?
    By Michiel in forum Qt Programming
    Replies: 1
    Last Post: 21st March 2006, 02:48

Tags for this Thread

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.