Results 1 to 20 of 21

Thread: Doubts related with QPainter & QVector

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2008
    Location
    Caracas - Venezuela
    Posts
    29
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Red face Doubts related with QPainter & QVector

    Well I have 2 questions but I have really no idea of what I can do to solve this.

    About QPainter:
    in the .h file:
    Qt Code:
    1. public:
    2. QVector<int> xpuntos;
    3. QVector<int> ypuntos;
    To copy to clipboard, switch view to plain text mode 
    In the cpp:
    Qt Code:
    1. r,paso, itemax,and i (defined).
    2.  
    3. for(r=0.0;r<=4.0;r+=paso){
    4. i=0;
    5. x0=qrand();
    6. x0/=RAND_MAX;
    7. while(i<itemax){
    8. x=r*x0*(1.0-x0);
    9. //if( (x-x0)<epsilon){
    10. // painter.drawPoint((int)(r*450.0/4.0),(int)(0-(x*450)));
    11. // break;
    12. //}
    13. x0=x;
    14. i++;
    15. if(i>250){
    16. xpuntos.append((int)(r*450.0/4.0));
    17. ypuntos.append((int)(0-(x*450)));
    18. }
    19. }
    20. }
    21. for(i=0;i<xpuntos.size();i++){
    22. painter.drawPoint(xpuntos.at(i),y.puntos.at(i)); //it could no determine type ....
    23. }
    To copy to clipboard, switch view to plain text mode 
    The error is Qt doesn't recognize the type. why it cant determine type?

    About QVector:
    in the .h file:
    Qt Code:
    1. QVector<QPoints> puntos;
    To copy to clipboard, switch view to plain text mode 
    In the cpp:
    My idea was inserting calculated data
    i have 100 points with positions double x, double y.For example:
    Qt Code:
    1. x=0.0, y=1;
    2. for(i=0;i<itmax;i++){
    3. x+=0.01
    4. y=C*y0*(1.0-y0);
    5. //Now the question... how I could add correctly this values to the QPoints vector?. My idea was:
    6. puntos.append( puntos.setX( (int) x, puntos.setY( (int) y) );
    7. }
    To copy to clipboard, switch view to plain text mode 
    It doesn't worked.... any other idea?
    Last edited by j0rt4g4; 2nd December 2008 at 05:31.

  2. #2
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Doubts related with QPainter & QVector

    try

    Qt Code:
    1. QVector<QPoint> puntos;
    2.  
    3. ...
    4.  
    5. puntos.append(QPoint(int(x),int(y)));
    To copy to clipboard, switch view to plain text mode 

    as for the unrecognized type, can you post the error mesage you get?

  3. #3
    Join Date
    Nov 2008
    Location
    Caracas - Venezuela
    Posts
    29
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Doubts related with QPainter & QVector

    And to access that "QVector<QPoints>" this will be the way?
    Qt Code:
    1. for(i=0;i<puntos.size(); i++){
    2. painter.drawPoint(puntos.at(i));
    3. }
    To copy to clipboard, switch view to plain text mode 
    In archive " If I use painter.draw crashes.zip (9.6 KB)" and it doesnt paint in the "widget" ... at all...

    and "Unrecogniced type.zip (10.1 k) " reflects my doubt number #1. thanks
    Attached Files Attached Files

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Doubts related with QPainter & QVector

    Quote Originally Posted by j0rt4g4 View Post
    And to access that "QVector<QPoints>" this will be the way?
    Qt Code:
    1. for(i=0;i<puntos.size(); i++){
    2. painter.drawPoint(puntos.at(i));
    3. }
    To copy to clipboard, switch view to plain text mode 
    Yet better using QPainter::drawPoints():
    Qt Code:
    1. painter.drawPoints(&puntos.at[0], puntos.count());
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. #5
    Join Date
    Nov 2008
    Location
    Caracas - Venezuela
    Posts
    29
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Doubts related with QPainter & QVector

    Quote Originally Posted by jpn View Post
    Yet better using QPainter::drawPoints():
    Qt Code:
    1. painter.drawPoints(&puntos.at[0], puntos.count());
    To copy to clipboard, switch view to plain text mode 
    It can't be just like that. I tried:
    Qt Code:
    1. for(long int i=0;i<250;i++){
    2. painter.drawPoints(&puntos.at(i), puntos.count());
    3. //painter.drawPoint(i,50);
    4. }
    To copy to clipboard, switch view to plain text mode 


    What I want is to generate pointsF when I click "Generar"
    and to paint on the widget called "widget" when I click in Pintar.
    But when I click Paint.... and I did this code for drawing on it like this:
    Qt Code:
    1. QPainter painter(widget);
    2. painter.setPen(Qt::white);
    3. QBrush brush(1);
    4. brush.setColor(QColor::fromRgbF(1,1,1,1));
    5. painter.setBrush(brush);
    6. painter.drawRect(0,0,450,450); //draw a white rect
    To copy to clipboard, switch view to plain text mode 
    It doesn't draw anything.... and how can I see if the slot "Generar" is working Correctly?... :S

    I dont know if I have to make it "current()" of something like that to draw on it..
    It draws when I use QPainter painter(this) but it draw in the whole windows, and I need it draws in the object called widget.
    Attached Files Attached Files
    Last edited by j0rt4g4; 5th December 2008 at 06:12.

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Doubts related with QPainter & QVector

    Why "it can't be like that"? There is no point to call drawPoints() in a loop, because it already takes an ARRAY of points. The whole idea of drawPoints() is the take all the points in a group so that you don't have to call drawPoint() for each and every point.

    When it comes to the visible result on the screen, there is no difference between these two:
    Qt Code:
    1. for(i=0;i<puntos.size(); i++){
    2. painter.drawPoint(puntos.at(i));
    3. }
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. painter.drawPoints(&puntos.at[0], puntos.count());
    To copy to clipboard, switch view to plain text mode 
    The latter is just more efficient.
    J-P Nurmi

  7. #7
    Join Date
    Nov 2008
    Location
    Caracas - Venezuela
    Posts
    29
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Doubts related with QPainter & QVector

    Quote Originally Posted by jpn View Post
    Why "it can't be like that"?
    Qt Code:
    1. for(i=0;i<puntos.size(); i++){
    2. painter.drawPoint(puntos.at(i));
    3. }
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. painter.drawPoints(&puntos.at[0], puntos.count());
    To copy to clipboard, switch view to plain text mode 
    The latter is just more efficient.
    Thank you for aswering because there is a tiny diference between them...
    If you use "[]" or "()" of course there's a diference.
    If I use "[]" i got this mistake: Invalid types' <unknown types>[int]' for array suscript.
    I got your point and you're rigth is more eficient do it like this:
    Qt Code:
    1. painter.drawPoints(&puntos.at(0), puntos.count());
    To copy to clipboard, switch view to plain text mode 

    If but I got the problem If I use:
    Qt Code:
    1. QPainter painter(this) // it draws in the whole windows
    2. QPainter painter(widget) // it doesn't draws at all
    To copy to clipboard, switch view to plain text mode 
    Why is happening this?. I have no clue
    Last edited by j0rt4g4; 5th December 2008 at 12:56.

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Doubts related with QPainter & QVector

    Quote Originally Posted by j0rt4g4 View Post
    If but I got the problem If I use:
    Qt Code:
    1. QPainter painter(this) // it draws in the whole windows
    2. QPainter painter(widget) // it doesn't draws at all
    To copy to clipboard, switch view to plain text mode 
    Why is happening this?. I have no clue
    A widget can only paint on itself. It can NOT paint on other widgets. Reimplement the paintEvent() handler of THAT widget you want to paint on.
    J-P Nurmi

  9. #9
    Join Date
    Nov 2008
    Location
    Caracas - Venezuela
    Posts
    29
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Doubts related with QPainter & QVector

    mmmm And how I can do that?
    I used designer to promote this widget called "widget" so I could create .h file and .cpp file about the "writing area" but I dont know if that what you meant.

  10. #10
    Join Date
    Nov 2008
    Location
    Caracas - Venezuela
    Posts
    29
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Doubts related with QPainter & QVector

    Well I will keep my doubt... And check if in other forum give me an answer... thanks

  11. #11
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Doubts related with QPainter & QVector

    Quote Originally Posted by j0rt4g4 View Post
    mmmm And how I can do that?
    I used designer to promote this widget called "widget" so I could create .h file and .cpp file about the "writing area" but I dont know if that what you meant.
    So put your painting code into that class. Reimplement the paintEvent() function of that class as usual. Don't try to open a painter on that widget in another class.
    J-P Nurmi

  12. #12
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Doubts related with QPainter & QVector

    Quote Originally Posted by j0rt4g4 View Post
    Qt Code:
    1. painter.drawPoint(xpuntos.at(i),y.puntos.at(i)); //it could no determine type ....
    To copy to clipboard, switch view to plain text mode 
    Notice "y.puntos" vs. "ypuntos". Next time please paste the error message.
    J-P Nurmi

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.