Results 1 to 12 of 12

Thread: GraphicsView Foreground

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2009
    Location
    India
    Posts
    143
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default GraphicsView Foreground

    Hi all,

    I have sub-classed graphics view and i have implemented "draw foreground" function ..I need to draw ellipse's on the view foreground...Provided my code for reference .

    Header File:

    Qt Code:
    1. #include <QGraphicsView>
    2.  
    3. class MyView: public QGraphicsView
    4. {
    5. Q_OBJECT
    6.  
    7. public:
    8.  
    9. MyView(QWidget *parent = 0);
    10.  
    11. protected:
    12.  
    13. void drawForeground(QPainter * painter, const QRectF & rect);
    14.  
    15.  
    16. };
    To copy to clipboard, switch view to plain text mode 


    Source File:

    Qt Code:
    1. #include <QtGui>
    2. #include <QX11Info>
    3.  
    4. #include "graphics.h"
    5.  
    6.  
    7. MyView::MyView(QWidget *parent) : QGraphicsView(parent)
    8.  
    9. {
    10.  
    11.  
    12. //--- Graphics View Properties
    13.  
    14. this->resize ( 768, 768 );
    15.  
    16.  
    17.  
    18. this->setStyleSheet("background-image: url(/aegean-120km.png)");
    19.  
    20. /*
    21.  
    22.   QGraphicsScene scene;
    23.  
    24.   scene.setSceneRect (0,0, 768, 768 );
    25.  
    26.   this->setScene ( &scene );
    27.  
    28. */
    29.  
    30. QColor color(Qt::yellow);
    31.  
    32. QBrush brush(color, Qt::SolidPattern);
    33.  
    34. this->setForegroundBrush(brush);
    35.  
    36.  
    37. this->show();
    38.  
    39.  
    40.  
    41.  
    42. }
    43.  
    44.  
    45. void MyView::drawForeground(QPainter * painter, const QRectF & rect)
    46. {
    47.  
    48. QColor color1(156, 189, 176,254);
    49.  
    50. painter->setPen(Qt::lightGray);
    51.  
    52. int x,y,w,h,i;
    53.  
    54. double centre_x=384, centre_y=384;
    55.  
    56. double step_size=38.5;
    57.  
    58. for(i=1;i<=20 ;i++)
    59. {
    60. x = centre_x - step_size * i ;
    61. y = centre_y - step_size * i ;
    62.  
    63. w=h=step_size * i * 2;
    64.  
    65. painter->drawEllipse(x,y,w,h);
    66. }
    67.  
    68. }
    To copy to clipboard, switch view to plain text mode 


    I didn't get any ellipse on the foreground ....By ref to manual Whether "draw foreground " function will be applicable only to QGraphicsScene ? how the draw foreground function will get called, automatically or any update mechanism need to be added in the code ...

    Please advise..
    Attached Images Attached Images

Similar Threads

  1. QGraphicsView Draw Foreground
    By augusbas in forum Qt Programming
    Replies: 4
    Last Post: 22nd June 2011, 13:01
  2. QGLWidget Render Text in the foreground
    By arpspatel in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2010, 11:35
  3. How to keep window in foreground
    By szicsi in forum Qt Programming
    Replies: 5
    Last Post: 17th January 2008, 14:40
  4. Painting: How to control what's in the foreground?
    By Mister_Crac in forum Qt Programming
    Replies: 16
    Last Post: 8th May 2007, 13:00
  5. Updating Foreground for QGraphicsView
    By tts80 in forum Qt Programming
    Replies: 5
    Last Post: 4th January 2007, 15:28

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.