PDA

View Full Version : problem with drawing rectangles on pixmap if the pixmap's height is too long



szakos
19th April 2011, 01:22
Hi i am very newbie.
I want to generate a picture, which shows the n-bit gray code, it is like binary code just in another order.
I used QPixmap and QLabel for showing the pic and QPainter to create little rectangles.
My problem is: if the bitek2 is greater than 11 the painter doesn't paint the whole pixmap. The gray_code() and the print_bin2() work correctly, I watched them in debug mode. I don't know why can't drawing correctly..
source:


QString bitek = ui->lineEdit->text();
bool ok;
int bitek2 = bitek.toInt(&ok,10);
if(!ok)
QMessageBox::information(this, tr("Baj van."),tr("Az ok %1 ").arg(ok));
else{

int kbitek2 = int(pow(2,bitek2));
QPixmap pixmap(bitek2*10, kbitek2*10 );

// pixmap.fill(Qt::green);
QPainter painter( &pixmap );
painter.setBrush(Qt::black);
painter.setPen(Qt::white);


for(int i=0;i<kbitek2;i++){
// ulong g = gray_code(i);
QString itt = print_bin2("", gray_code(i), bitek2);

for(int j=0;j<bitek2;j++){

if(itt[j]=='1'){

painter.setBrush(Qt::black);
painter.drawRect(j*10, i*10, 10,10);

// painter.drawPoint(j,i);
}
else if (itt[j]=='.') {
painter.setBrush(Qt::cyan);
painter.drawRect(j*10, i*10, 10,10);
}

}
}


ui->imageLabel->setPixmap(pixmap);

qDebug()<<pixmap.depth();

// ui->imageLabel->resize(bitek2,kbitek2);
ui->imageLabel->adjustSize();

}
62516252
Sorry for bad English.

high_flyer
19th April 2011, 11:17
This:

QPixmap pixmap(bitek2*10, kbitek2*10 );
Will result in a pixmap size which is 120 x 40960 = 4915200 pixels!! for: kbitek2 = 12
I don't know for sure, but this could be well over the limit for QPixmap size. (which is based on OS limitations for bitmap size and other things).
Try using a QImage, and scale it down to some QPixmap size you know to work.