Hello all,

I'm working towards a more complex use for QImage and QPixmap, but for now I'm still trying to overcome this fundamental issue I see:

I am using this short code below with QT4 to show a Pixmap via a QLabel, but what I see is only half correct (see code and image below).


Qt Code:
  1. #include "widget.h"
  2. #include "ui_widget.h"
  3.  
  4. #include <QPainter>
  5. #include <QPaintDevice>
  6. #include <QLabel>
  7. #include <iostream>
  8. #include <QImage>
  9. #include <QPixmap>
  10.  
  11. using namespace std;
  12.  
  13.  
  14. Widget::Widget(QWidget *parent) :
  15. QWidget(parent),
  16. ui(new Ui::Widget)
  17. {
  18. ui->setupUi(this);
  19.  
  20.  
  21. for(int i=0;i<100;i++)
  22. {
  23. for(int j=0;j<100;j++)
  24. {
  25.  
  26.  
  27. myimage = QImage(100,100,QImage::Format_RGB32);
  28. QRgb colorval;
  29. colorval = qRgb(i,j,50);
  30.  
  31. myimage.setPixel(j,i,colorval);
  32. cout << " Setting " << i << " " << j << endl;
  33.  
  34.  
  35.  
  36. }
  37.  
  38.  
  39. }
  40.  
  41.  
  42.  
  43.  
  44. QPixmap mypixmap = QPixmap::fromImage(myimage);
  45. mylabel = new QLabel;
  46. mylabel->setPixmap(mypixmap);
  47. mylabel->setScaledContents(true);
  48. mylabel->show();
  49.  
  50.  
  51. }
  52.  
  53. Widget::~Widget()
  54. {
  55. delete ui;
  56. }
To copy to clipboard, switch view to plain text mode 

From this code I expect each pixel to be colorized and not what actually occurs (See image):

screencap.jpg

Can anyone please explain to me the reason these black lines are present in my image?

If i and j are swapped, the lines become horizontal. Additionally, if a second loop is added with (i+1, j+1) the lines are covered.

Thank you,