Results 1 to 18 of 18

Thread: QGraphicsView: Images doesn't fit view frame

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2013
    Posts
    22
    Thanks
    1
    Qt products
    Qt5

    Default Re: QGraphicsView: Images doesn't fit view frame

    It seems that there is no solution for QGraphicsView. I'm looking at QLabel which also provides support for QPixmap and looks it's easier to show image in here. What would be the command for fitting image into QLabel, because scaledContents only scale image, so it doesn't keep ratio?

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

    Default Re: QGraphicsView: Images doesn't fit view frame

    There is no equivalent. You can implement a custom widget that does what you want or use QGraphicsView. I assure you the latter works, I've used in many times like that. However implementing a custom widget is very easy.
    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.


  3. #3
    Join Date
    Jun 2013
    Posts
    22
    Thanks
    1
    Qt products
    Qt5

    Default Re: QGraphicsView: Images doesn't fit view frame

    I found another code on web and adjusted it to my project, but it's same as before. I really don't know what could be wrong and as well I don't understand you last tips - probably because I'm into Qt only few weeks. Here is my current code:
    Qt Code:
    1. image = new QImage(filePath);
    2. scn = new QGraphicsScene(this);
    3. ui->graphicsView->setScene(scn);
    4. scn->addPixmap(QPixmap::fromImage(*image));
    5. scn->setSceneRect(0,0,image->width(),image->height());
    6. ui->graphicsView->fitInView(scn->sceneRect(),Qt::KeepAspectRatioByExpanding);
    To copy to clipboard, switch view to plain text mode 

    What can I do to fit image into this frame?

    Thank you very much!

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

    Default Re: QGraphicsView: Images doesn't fit view frame

    I already told you -- you cannot call fitInView() before the view is first shown because it has no size yet. You can find as many "codes on web" but they will all fail because of the same reason. You need to do as I told you -- call fitInView() when the view is already visible.
    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.


  5. #5
    Join Date
    Jun 2013
    Posts
    22
    Thanks
    1
    Qt products
    Qt5

    Default Re: QGraphicsView: Images doesn't fit view frame

    Ok, I see what's the problem. But how can I do that image would fit the frame on setup of dialog?

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

    Default Re: QGraphicsView: Images doesn't fit view frame

    Am I wasting my time here? Did you read post #11? You have two possible solutions there. And in #13 there is a suggestion to implement a custom widget that draws a resized pixmap. It's as easy as subclassing QWidget, reimplementing its paintEvent() and calling QPainter::drawPixmap().
    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.


  7. The following user says thank you to wysota for this useful post:

    janck (13th June 2013)

  8. #7
    Join Date
    Jun 2013
    Posts
    22
    Thanks
    1
    Qt products
    Qt5

    Default Re: QGraphicsView: Images doesn't fit view frame

    Sorry, I didn't know that showEvent() also exists for Dialogs. This solved my problem, so thank you!

Similar Threads

  1. QPixMap doesn't show one of two images !
    By ladiesfinger in forum Qt Programming
    Replies: 5
    Last Post: 10th January 2011, 16:29
  2. QGraphicsView Frame Rate
    By benlau in forum Qt Programming
    Replies: 11
    Last Post: 13th October 2010, 01:04
  3. How to drag and drop on QGraphicsView frame
    By wudelei in forum Qt Programming
    Replies: 1
    Last Post: 16th April 2010, 08:04
  4. Application doesn't display images
    By satoshi in forum Qt Programming
    Replies: 3
    Last Post: 2nd January 2010, 11:33
  5. Simple frame control doesn't resize when I hide()
    By MrGarbage in forum Qt Programming
    Replies: 2
    Last Post: 29th August 2007, 22:32

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