Results 1 to 3 of 3

Thread: passing QVector of QPoints to a widget's paintEvent

  1. #1
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default passing QVector of QPoints to a widget's paintEvent

    I have an array of data in the main part of my application. I want to use these values to paint a subclassed widget. I've set it up like so:

    Qt Code:
    1. // mainApp.cpp
    2.  
    3. QVector<QPoint> points(4000);
    4.  
    5. for(int a=0; a<4000; a++)
    6. {
    7. points[a].setX( getX_from_elsewhere() );
    8. points[a].setY( getY_from_elsewhere() );
    9. }
    10.  
    11. ptrSubclassedWidget->draw(points);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // subClassedWidget.h
    2.  
    3. private:
    4. QVector<QPoint> wellData;
    5.  
    6. public:
    7. void draw( QVector<QPoint> dataIn);
    8.  
    9. protected:
    10. void paintEvent(QPaintEvent *pe);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // subClassedWidget.cpp
    2.  
    3. void subClassedWidget::draw(QVector<QPoint> dataIn);
    4. {
    5. wellData = dataIn;
    6. update();
    7. }
    8.  
    9. void subClassedWidget::paintEvent(QPaintEvent *pe)
    10. {
    11. // doesn't work for obvious reason: wellData not an *array* of QPoints, but a Vector of QPoints
    12. painter.drawPolyline(wellData, 4000);
    13. }
    To copy to clipboard, switch view to plain text mode 

    So, questions:

    1. I know how to draw a polyLine based on an *array* of QPoint. How can I do this using a Vector of QPoints?
    2. Should I be passing the QVector to draw() by reference?

  2. #2
    Join Date
    Apr 2009
    Posts
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: passing QVector of QPoints to a widget's paintEvent

    Hi,
    you can use data member of QVector to retrieve its data as an array.

    Qt Code:
    1. painter.drawPolyline(wellData.data(), 4000);
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to zaghaghi for this useful post:

    vonCZ (1st May 2009)

  4. #3
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: passing QVector of QPoints to a widget's paintEvent

    Thank you! One other thing: I had to replace "4000" with wellData.size():

    Qt Code:
    1. painter.drawPolyline(wellData.data(), wellData.size());
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 0
    Last Post: 11th November 2008, 15:36
  2. Possible to use a widget in another widget's paintEvent?
    By robot_love in forum Qt Programming
    Replies: 2
    Last Post: 9th September 2008, 05:18
  3. passing a QPainter object to widgets
    By vratojr in forum Qt Programming
    Replies: 9
    Last Post: 11th January 2006, 15:27

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.