Results 1 to 3 of 3

Thread: QPixmap::operator=: Cannot assign to pixmap during painting

  1. #1
    Join Date
    Sep 2010
    Posts
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QPixmap::operator=: Cannot assign to pixmap during painting

    Hey,

    I'm currently making my own tablewidget because i want to have more than a thousand rows and columns and QTableWidget takes too much memory.
    So i started working on it, and this is what i currently have:

    Qt Code:
    1. //mytable.cpp
    2. #include <QtGui/QApplication>
    3. #include <QtGui/QMainWindow>
    4. #include <QtGui/QColor>
    5. #include <QtGui/QBrush>
    6. #include "mytable.h"
    7.  
    8. mytable::mytable( QWidget* parent) : QWidget( parent ) {
    9. }
    10.  
    11. void mytable::paintEvent( QPaintEvent* event ) {
    12. QPainter* painter=new QPainter(this);
    13. QSize _size = size();
    14. QBrush brush( QColor(0,150,0)/*, Qt::LinearGradientPattern*/);
    15. painter->fillRect(0,0, _size.width(), 20, brush );
    16. painter->fillRect(0,0, 30, _size.height() , brush);
    17. painter->setPen(QColor(0,0,0));
    18. for( int x = 30; x<= _size.width();x+=80 ) {
    19. painter->drawLine( x, 0, x, _size.height() );
    20. }
    21. for( int y = 20; y <= _size.height(); y+=20){
    22. painter->drawLine(0, y, _size.width(), y );
    23. }
    24. }
    25.  
    26. /*void mytable::drawHeaders( QPainter* painter, QSize _size ) {
    27.  
    28. }*/
    29. int main( int argc, char** argv) {
    30. QApplication app( argc, argv );
    31. w.setGeometry(0,0,600,600);
    32. mytable table( &w );
    33. table.setGeometry(0,0,600,600);
    34. w.show();
    35. return app.exec();
    36. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. //mytable.h
    2. #ifndef MYTABLE_H
    3. #define MYTABLE_H
    4.  
    5. #include <QtGui/QWidget>
    6. #include <QtGui/QPainter>
    7.  
    8. class mytable : public QWidget {
    9.  
    10. public:
    11. mytable(QWidget*);
    12. protected:
    13. void paintEvent( QPaintEvent* );
    14. void drawHeaders(QPainter*, QSize );
    15.  
    16. };
    To copy to clipboard, switch view to plain text mode 

    Compiling works fine, but if i run, the widget shows up, but i get the following error
    if i resize the widget:
    Qt Code:
    1. QPixmap::operator=: Cannot assign to pixmap during painting
    To copy to clipboard, switch view to plain text mode 

    And this error if i close the widget:
    Qt Code:
    1. QPaintDevice: Cannot destroy paint device that is being painted
    To copy to clipboard, switch view to plain text mode 

    What can i do to solve this errors?

    regards, hannesvdc

  2. #2
    Join Date
    Mar 2010
    Posts
    11
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPixmap::operator=: Cannot assign to pixmap during painting

    I think its because you are not deleting pointer to QPainter inside paintEvent().

  3. The following 2 users say thank you to JackHammer for this useful post:

    uatek (6th February 2012), zeFree (1st November 2013)

  4. #3
    Join Date
    Sep 2010
    Posts
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap::operator=: Cannot assign to pixmap during painting

    Hey, thanks, a call to painter->end or delete painter solves to problem!

    regards, hannesvdc

  5. The following user says thank you to hannesvdc for this useful post:

    zeFree (1st November 2013)

Similar Threads

  1. Cannot assign to pixmap during painting
    By fanatos in forum Qt Programming
    Replies: 9
    Last Post: 22nd February 2016, 17:56
  2. Replies: 3
    Last Post: 16th April 2010, 07:56
  3. Painting into QPixmap
    By jessiemmichael in forum Qt Programming
    Replies: 5
    Last Post: 8th September 2009, 09:12
  4. QPixmap: X11 "memory leak" due to shared pixmap data?
    By chezifresh in forum Qt Programming
    Replies: 0
    Last Post: 21st April 2009, 19:53
  5. boost::assign
    By Sivert in forum General Programming
    Replies: 0
    Last Post: 2nd May 2007, 00:23

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.