Results 1 to 2 of 2

Thread: problem with drawing rectangles on pixmap if the pixmap's height is too long

  1. #1
    Join Date
    Apr 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Question problem with drawing rectangles on pixmap if the pixmap's height is too long

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,710
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: problem with drawing rectangles on pixmap if the pixmap's height is too long

    This:
    Qt Code:
    1. QPixmap pixmap(bitek2*10, kbitek2*10 );
    To copy to clipboard, switch view to plain text mode 
    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. QTableWidget Pixmap problem
    By batileon in forum Qt Programming
    Replies: 3
    Last Post: 28th March 2018, 15:39
  2. label - pixmap - problem
    By qwrhiobasdbgghoasdf in forum Newbie
    Replies: 5
    Last Post: 16th September 2010, 00:29
  3. Pixmap scaling problem
    By tommy in forum Qt Programming
    Replies: 1
    Last Post: 14th May 2009, 17:00
  4. Drawing pixmap with subpixel precision
    By Angelo Moriconi in forum Qt Programming
    Replies: 0
    Last Post: 24th October 2008, 08:53
  5. Pixmap height / width without loading it
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2007, 07:10

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.