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.
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.