Results 1 to 8 of 8

Thread: Changing painter settings for QPixmap

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2008
    Location
    Murfreesboro, TN
    Posts
    10
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Question Changing painter settings for QPixmap

    I keep getting an unhandled exception when I do the following:

    QPixmap p;

    p = new QPixMap(600, 2500);

    // crashes out on the set...will also crash out on anything tied to the painter.
    p->paintEngine()->painter()->setPen(Qt::blue);

    I figure I am doing a horribly novice mistake here so any help would be awesome.

    Thanks for your time,
    Jon Jones
    Last edited by spagatoni; 22nd October 2008 at 03:31.

  2. #2
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Changing painter settings for QPixmap

    What are you trying to do? I've never seen someone access the paintEngine directly like that, I'm not sure you're allowed.

  3. #3
    Join Date
    Oct 2008
    Location
    Murfreesboro, TN
    Posts
    10
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Changing painter settings for QPixmap

    I am reading in a large set of data and using QwtPlot to render the data. Due to the way the data is coming in I want to plot the points to a QPixmap and then render them to the screen.

    I can get the system to render the points to the Pixmap by doing:

    p->paintEngine()->drawPoints(...);

    but I need to render each of the points in a certain color based on a value from the data. that is why I attempt to set the pen with:

    p->paintEngine()->painter()->setPen(...);

    I hope I cleared that up. If not let me know.

    Thanks for the quick reply,
    Jon Jones

  4. #4
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Changing painter settings for QPixmap

    As for your current error, I'm not sure. I've never done it this way. Its possible someone else may be able to help further. The fact that you have to go through so many calls to get to the painter object throws up flags for me.

    From what you've described, it seems more correct to instantiate a QPainter and pass into its constructor the pixmap as the paint device, and then do your painting. I could be wrong though.

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

    spagatoni (22nd October 2008)

  6. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Changing painter settings for QPixmap

    Quote Originally Posted by spagatoni View Post
    I am reading in a large set of data and using QwtPlot to render the data. Due to the way the data is coming in I want to plot the points to a QPixmap and then render them to the screen.
    Painting a curve ( or any other plot item ) to a pixmap and painting it instead will erase all other plot items (beside the pixmap has a transparent background), that are below the curve ( f.e. the grid ).

    If your intention is, that you don't want to have all your data in memory at once, better derive from QwtData. The Qwt framework always iterates over the data object in increasing order, so you can load/discard your data in pieces.
    Otherwise write your intention. I'm pretty sure the best solution will be different from what you have in mind.

    Uwe

  7. The following user says thank you to Uwe for this useful post:

    spagatoni (22nd October 2008)

  8. #6
    Join Date
    Oct 2008
    Location
    Murfreesboro, TN
    Posts
    10
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Changing painter settings for QPixmap

    Quote Originally Posted by JimDaniel View Post
    From what you've described, it seems more correct to instantiate a QPainter and pass into its constructor the pixmap as the paint device, and then do your painting. I could be wrong though.
    This may be a silly question but exactly what do you mean? This is a quick snippet of what I thought you meant:

    QPixmap _pixMap = QPixmap::grabWidget(widget);

    // Is this what you intend? Cause this crashes the system
    QPainter *pixMapPainter = new QPainter(_pixMap.paintEngine()->paintDevice());

    pixMapPainter->setPen(...);
    pixMapPainter->drawPoint(x,y);

    Thanks,
    Jon Jones

  9. #7
    Join Date
    Oct 2008
    Location
    Murfreesboro, TN
    Posts
    10
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Changing painter settings for QPixmap

    After looking around I at least figured out what you meant by instantiate the QPainter by using the QPixmap but now it isn't drawing anything to the pixmap.

    The following is what I do for rendering to the pixmap...I think I am missing something..not sure what though:

    Qt Code:
    1. QPainter pixMapPainter(&pixMap);
    2. pixMapPainter.setPen(Qt::red);
    3. pixMapPainter.drawPoint(x, y);
    To copy to clipboard, switch view to plain text mode 

    Thanks for the help,
    Jon Jones

  10. #8
    Join Date
    Oct 2008
    Location
    Murfreesboro, TN
    Posts
    10
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Talking Re: Changing painter settings for QPixmap

    Quote Originally Posted by spagatoni View Post
    After looking around I at least figured out what you meant by instantiate the QPainter by using the QPixmap but now it isn't drawing anything to the pixmap.

    The following is what I do for rendering to the pixmap...I think I am missing something..not sure what though:

    Qt Code:
    1. QPainter pixMapPainter(&pixMap);
    2. pixMapPainter.setPen(Qt::red);
    3. pixMapPainter.drawPoint(x, y);
    To copy to clipboard, switch view to plain text mode 

    Thanks for the help,
    Jon Jones

    Actually the above code does work. I had an issue elsewhere in the system so it functions correctly now!

    Thanks for all the help and the pushes in the right direction I appreciate it greatly JimDaniel and Uwe!

    Thanks,
    Jon Jones

Similar Threads

  1. Problem with Painter in Qt4.4.1
    By merry in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2008, 13:47
  2. Scaling
    By AD in forum Qt Programming
    Replies: 16
    Last Post: 11th July 2008, 10:55

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
  •  
Qt is a trademark of The Qt Company.