Results 1 to 2 of 2

Thread: Why doesn't the line appear on my Image?

  1. #1
    Join Date
    Apr 2009
    Location
    Earth
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Smile Why doesn't the line appear on my Image?

    Hi everybody out there using Qt4, I am doing a simple experiment using Qt4, I just wanna draw lines on a loaded image, here's the paintEvent code:
    Qt Code:
    1. void GpsLocator::paintEvent(QPaintEvent *event){
    2. image=new QImage();
    3. image->load(*imageName);
    4. windowPainter=new QPainter(this);
    5. windowPainter->initFrom(this);
    6. windowPainter->drawImage(0,0,*image);
    7. this->setMinimumSize(image->width(),image->height());
    8. imagePainter=new QPainter(image);
    9. imagePainter->setPen(QPen(Qt::DotLine));
    10. imagePainter->drawLine(218,223,433,375);
    11. }
    To copy to clipboard, switch view to plain text mode 
    but this doesn't work, while the image is loaded successfully, but the line doesn't appear, I am just wondering how this could happen? Can anyone do me a favor, many thanks!

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

    Default Re: Why doesn't the line appear on my Image?

    The code is all wrong. Do you by any chance come from the Java world? It looks you are used to having a garbage collector and allocating everything on the heap. Don't do that with QImage and QPainter. Furthermore don't put the code in paintEvent as it may be called without you knowing and it is crucial that it executes as fast as possible. Fix the errors and then we can continue.
    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.


Similar Threads

  1. Why is my application's CPU usage always > 50%
    By richardander in forum Qt Programming
    Replies: 10
    Last Post: 14th October 2010, 22:22
  2. QTcpSocket exception.
    By Fastman in forum Qt Programming
    Replies: 9
    Last Post: 29th January 2008, 13:51
  3. Qwizard crashed when created in a slot
    By joshlareau in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2008, 09:16
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42

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.