Results 1 to 3 of 3

Thread: problem in drawing image in QLabel!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2008
    Posts
    154
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default problem in drawing image in QLabel!

    hi every body;
    i am facing a problem in drawing Image in a QLabel
    i used the follwoing code to draw the image
    Qt Code:
    1. m_pQiblaImage = new QImage(QSize(289,289),QImage::Format_ARGB32_Premultiplied);
    2. m_pPainter = new QPainter(m_pQiblaImage);
    3. m_pPainter->setCompositionMode(QPainter::CompositionMode_SourceOver);
    4. m_pPainter->translate(144.5,144.5);
    5. m_pPainter->save();
    6.  
    7. //Compass background
    8. QString fileName(IMAGES_PATH);
    9. fileName.append("compass.png");
    10. QImage source(fileName);
    11. m_pPainter->rotate(360 - angleToNorth);
    12. m_pPainter->drawImage(-144.5,-144.5,source);
    13. // m_pPainter->restore();
    14. //m_pPainter->save();
    15.  
    16. fileName.clear();
    17. fileName.append(IMAGES_PATH);
    18. fileName.append("Qibla-needle.png");
    19. source.load(fileName);
    20. m_pPainter->rotate(NormalizeTo360(m_qibla-90/*+ (360-angleToNorth)*/));
    21. m_pPainter->drawImage(-114.5,-20.5,source);
    22. // m_pPainter->restore();
    23. //m_pPainter->save();
    24.  
    25. if(QTime::currentTime() < m_prayerTimes[4] && QTime::currentTime() > m_prayerTimes[1] && m_gpsMode != 2/*ON*/)
    26. {
    27. //qDebug()<<"current time is "<< QTime::currentTime();
    28. //qDebug()<<"prayer Time = "<<m_prayerTimes[5];
    29. fileName.clear();
    30. fileName.append(IMAGES_PATH);
    31. fileName.append("sun-needle.png");
    32. source.load(fileName);
    33. m_pPainter->rotate(360 - NormalizeTo360(getSunQiblaDir(m_CityInfo.longitude, m_CityInfo.latitude) * DPR)/*+(360 - angleToNorth)*/);
    34. m_pPainter->drawImage(-114.5,-20.5,source);
    35. m_pPainter->restore();
    36. m_pPainter->save();
    37. }
    38. else
    39. {
    40. m_pPainter->restore();
    41. m_pPainter->save();
    42. }
    43. fileName.clear();
    44. fileName.append(IMAGES_PATH);
    45. fileName.append("Compass-needle.png");
    46. source.load(fileName);
    47. m_pPainter->rotate(360 - angleToNorth);
    48. m_pPainter->drawImage(-17.5,-106.5,source);
    49. m_pPainter->restore();
    50. m_pPainter->save();
    51.  
    52. fileName.clear();
    53. fileName.append(IMAGES_PATH);
    54. fileName.append("compass-center.png");
    55. source.load(fileName);
    56. m_pPainter->drawImage(-10.5,-10.5,source);
    57. m_pPainter->restore();
    58. m_pPainter->save();
    59.  
    60. fileName.clear();
    61. fileName.append(IMAGES_PATH);
    62. fileName.append("compass-glass.png");
    63. source.load(fileName);
    64. m_pPainter->drawImage(-144.5, -144.5,source);
    65. m_pPainter->end();
    66.  
    67. ui->compass->setPixmap(QPixmap::fromImage(*m_pQiblaImage));
    68. delete m_pQiblaImage;
    69. m_pQiblaImage=NULL;
    70. delete m_pPainter;
    71. m_pPainter =NULL;
    72. update(47, 33, 289, 289);
    To copy to clipboard, switch view to plain text mode 

    and i get the follwong result

    the compass image is a transparent PNG , the blue color should not be displayed because the part that contain blue color are in fact transparent so why it is displayed in blue rather than transparent?
    what is wrong? please help me to find a solution to this problem
    Last edited by mismael85; 28th March 2010 at 13:28.

Similar Threads

  1. Replies: 6
    Last Post: 21st September 2009, 10:55
  2. Problems with drawing image in paintEvent of QTreeView
    By Tito Serenti in forum Qt Programming
    Replies: 7
    Last Post: 24th December 2008, 23:25
  3. drawing over QLabel
    By tommy in forum Qt Programming
    Replies: 18
    Last Post: 17th November 2007, 18:39
  4. Replies: 3
    Last Post: 4th June 2007, 09:51
  5. Fast image drawing/scaling in Qt 3.3
    By eriwik in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2006, 10:45

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.