Results 1 to 8 of 8

Thread: Rotate items in qwt

  1. #1
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Rotate items in qwt

    im new to qwt

    i want to draw a grid in qwt, where it will look like a Rect (x1,y1, x2,y2, x3,y3,x4,y4) ... then i want to rotate it with a specific angle.

    so can anybody please help how can we rotate items in qwt is there any function such as QRect.rotate ("angle").
    and is the there a Rect item in qwt or i have to draw each line by it self.

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

    Default Re: Rotate items in qwt

    i want to draw a grid in qwt, where it will look like a Rect (x1,y1, x2,y2, x3,y3,x4,y4) ... then i want to rotate it with a specific angle.
    What type of coordinates are these: plot or widget coordinates ?

    so can anybody please help how can we rotate items in qwt is there any function such as QRect.rotate ("angle").
    Use QTransform.

    and is the there a Rect item in qwt or i have to draw each line by it self.
    In the navigation example you find a plot item, that displays a rectangle. The next version of Qwt ( available in SVN trunk ) will offer QwtPlotShapeItem, that displays any type of shape, that can be expressed by a QPainterPath - what includes a rectangle.

    The idea behind plot items is, that they will be mapped and displayed on the plot canvas according to the coordinate system of the axes. This mapping needs a translation and scaling, but no rotation. So this needs to be done inside the implementation of a plot item.

    Uwe

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

    jesse_mark (10th July 2012)

  4. #3
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rotate items in qwt

    Quote Originally Posted by Uwe View Post
    What type of coordinates are these: plot or widget coordinates ?

    im using plot coordinates and im usgin qwtcurve and give setdata and this is a snipt of the code ... it draw the rectangle

    QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
    QwtPointSeriesData* myData = new QwtPointSeriesData;
    QVector<QPointF>* samples = new QVector<QPointF>;
    samples->push_back(QPointF(1000,1000)); // my origin
    samples->push_back(newPosition(100,100,8200,1000,-30));
    samples->push_back(newPosition(100,100,8200,8200,-30));
    samples->push_back(newPosition(100,100,1000,8200,-30));
    samples->push_back(QPointF(1000,1000));
    myData->setSamples(*samples);
    curve1->setData(myData);

    curve1->setBrush(mybrush);

    curve1->setPen(p);

    curve1->attach(ui->qwtPlot);

    Quote Originally Posted by Uwe View Post
    Use QTransform.
    do you mind tell me how can i use QTransform with qwtcurve ??

    thank you so much

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

    Default Re: Rotate items in qwt

    Quote Originally Posted by jesse_mark View Post
    do you mind tell me how can i use QTransform with qwtcurve ??
    You can't - but you can use QTransform to rotate a rectangle ( or any other polygon ):

    Qt Code:
    1. QTransform transform;
    2. transform.translate( rect.topLeft() ); // origin of your rotation
    3. transform.rotate( ... );
    4.  
    5. QPolygonF points = transform.mapToPolygon( QRectF( 0, 0, rect.width(), rect.height() );
    6.  
    7. ...
    To copy to clipboard, switch view to plain text mode 

    It's up to you to decide if this makes your code easier.

    Uwe

  6. #5
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rotate items in qwt

    but how can i display the QPolygon on qwtpolt after that ??

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

    Default Re: Rotate items in qwt

    Quote Originally Posted by jesse_mark View Post
    but how can i display the QPolygon on qwtpolt after that ??
    The same way like in your code above - or even easier this way:

    Qt Code:
    1. curve1->setSamples( polygon );
    To copy to clipboard, switch view to plain text mode 
    Uwe

  8. #7
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rotate items in qwt

    [QUOTE=Uwe;224305]
    Qt Code:
    1. QPolygonF points = transform.mapToPolygon( QRectF( 0, 0, rect.width(), rect.height() );
    To copy to clipboard, switch view to plain text mode 

    i used QRect as there is no transform.mapToPolygon takes QRectF

    this is what i wrote :

    Qt Code:
    1. QRect grid;
    2. grid.setTop(Ox);
    3. grid.setLeft(Oy);
    4. grid.setHeight(Hight);
    5. grid.setWidth(Width);
    6.  
    7.  
    8. QTransform Tr;
    9. Tr.translate(grid.top(),grid.left());
    10. Tr.rotate(30);
    11.  
    12. QPolygonF points = Tr.mapToPolygon(QRect(0, 0, grid.width(), grid.height()));
    13.  
    14. curve1->setSamples( points );
    To copy to clipboard, switch view to plain text mode 

    but the resulted graph was not rectangle it was

    qwt.jpeg

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

    Default Re: Rotate items in qwt

    It is a rectangle, but setting a curve brush means that the area below the points ( to the baseline ) is filled - not the area inside the polygon.

    But I already told you in my first answer what type of plot item you need. I recommend to copy the RectItem of the navigation example and modify it so that it works with polygons. In the draw method you have to transform the points of the polygon one by one ( instead of a rectangle once ).

    Another option is to keep the RectItem as it is, beside rotating the translated rectangle inside of the draw method - but I don't know your use case.

    Uwe

Similar Threads

  1. Replies: 3
    Last Post: 5th February 2012, 18:59
  2. Replies: 2
    Last Post: 20th August 2010, 06:18
  3. How to rotate a QMainWindow
    By viet in forum Qt Programming
    Replies: 4
    Last Post: 19th August 2010, 01:31
  4. Rotate QLabel
    By Qt Coder in forum Newbie
    Replies: 2
    Last Post: 19th March 2009, 12:25
  5. Rotate QLabel
    By shader76 in forum Newbie
    Replies: 9
    Last Post: 24th December 2007, 13:31

Tags for this Thread

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.