Results 1 to 6 of 6

Thread: I am having a minor problem with my code.

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default I am having a minor problem with my code.

    Please see code below. I've got an 842 x595 image and I want to split it into two images of size 421x595 each, hence I used the copy function. The copying works perfect and I am able the display the first copy of my Image in the view. Please see the attached image and the output to my program.background1.jpgOutput_screen1.jpg
    Qt Code:
    1. void Page::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    2. {
    3. painter->setBrush(Qt::NoBrush);
    4.  
    5. QImage image(directory);
    6. QImage frontPageBackground = image.copy(QRect(422,0,image.rect().width(),image.rect().height()));
    7. QImage backPageBackground = image.copy(QRect(0,0,image.rect().width()/2, image.rect().height()));
    8.  
    9. painter->drawImage(rect, backPageBackground );
    10. }
    To copy to clipboard, switch view to plain text mode 

    The problem comes when I want to display the second piece of the image and suddenly my scene looks like this.Output_screen2.jpg Please help guys. I know this is a minor problem but I just don't get why this is happening.

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: I am having a minor problem with my code.

    What is the width of your rect variable you're passing to QPainter::drawImage?

  3. #3
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: I am having a minor problem with my code.

    its the width of the image itself.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: I am having a minor problem with my code.

    Have you tried copying the first image also with half width?
    Line 6 of your snippet above uses rect.width() for the third argument of copy()

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    ayanda83 (5th April 2015)

  6. #5
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: I am having a minor problem with my code.

    It doesn't look like line 6 for frontPageBackground is used at all.

    Quote Originally Posted by ayanda83 View Post
    its the width of the image itself.
    The way I read it, you're painting only half the image. You create backPageBackground by copying half of the image's width, then you paint it in a rect that is the full size of the original image?

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

    ayanda83 (5th April 2015)

  8. #6
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: I am having a minor problem with my code.

    Quote Originally Posted by anda_skoa View Post
    Have you tried copying the first image also with half width?
    Line 6 of your snippet above uses rect.width() for the third argument of copy()

    Cheers,
    _
    Thank you. I knew that this was a small error. thank you for pointing it out to me.

Similar Threads

  1. Replies: 1
    Last Post: 14th April 2014, 06:27
  2. Qwt major and minor grid
    By endbegin in forum Qwt
    Replies: 2
    Last Post: 4th February 2012, 23:33
  3. draw minor arc
    By sujan.dasmahapatra in forum General Programming
    Replies: 2
    Last Post: 11th October 2011, 00:08
  4. Grid Minor Major and gap before the data
    By huseyinkozan in forum Qwt
    Replies: 3
    Last Post: 3rd August 2010, 12:13
  5. QComboBox minor problem
    By lalesculiviu in forum Qt Programming
    Replies: 2
    Last Post: 12th December 2009, 16:50

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.