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:
Qt Code:
  1. QString bitek = ui->lineEdit->text();
  2. bool ok;
  3. int bitek2 = bitek.toInt(&ok,10);
  4. if(!ok)
  5. QMessageBox::information(this, tr("Baj van."),tr("Az ok %1 ").arg(ok));
  6. else{
  7.  
  8. int kbitek2 = int(pow(2,bitek2));
  9. QPixmap pixmap(bitek2*10, kbitek2*10 );
  10.  
  11. // pixmap.fill(Qt::green);
  12. QPainter painter( &pixmap );
  13. painter.setBrush(Qt::black);
  14. painter.setPen(Qt::white);
  15.  
  16.  
  17. for(int i=0;i<kbitek2;i++){
  18. // ulong g = gray_code(i);
  19. QString itt = print_bin2("", gray_code(i), bitek2);
  20.  
  21. for(int j=0;j<bitek2;j++){
  22.  
  23. if(itt[j]=='1'){
  24.  
  25. painter.setBrush(Qt::black);
  26. painter.drawRect(j*10, i*10, 10,10);
  27.  
  28. // painter.drawPoint(j,i);
  29. }
  30. else if (itt[j]=='.') {
  31. painter.setBrush(Qt::cyan);
  32. painter.drawRect(j*10, i*10, 10,10);
  33. }
  34.  
  35. }
  36. }
  37.  
  38.  
  39. ui->imageLabel->setPixmap(pixmap);
  40.  
  41. qDebug()<<pixmap.depth();
  42.  
  43. // ui->imageLabel->resize(bitek2,kbitek2);
  44. ui->imageLabel->adjustSize();
  45.  
  46. }
To copy to clipboard, switch view to plain text mode 
gr11.pnggr12.png
Sorry for bad English.