Results 1 to 5 of 5

Thread: My first program with QGraphicsView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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: My first program with QGraphicsView

    I meant that for an ellipse you don't need to implement your own QGraphicsItem, you can simply use a QGrapgicsEllipseItem instead:
    Qt Code:
    1. #include <QApplication>
    2. #include <QGraphicsView>
    3. #include <QGraphicsScene>
    4.  
    5. int main( int argc, char **argv )
    6. {
    7. QApplication app(argc, argv);
    8.  
    9. QGraphicsScene scene(QRectF(0,0,100,100));
    10. scene.addEllipse(QRectF(25,40,50,20), QPen(Qt::green), QBrush(Qt::red));
    11. QGraphicsView view(&scene);
    12. view.show();
    13.  
    14. return app.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  2. #2
    Join Date
    Feb 2006
    Posts
    209
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: My first program with QGraphicsView

    With this constructor

    Qt Code:
    1. Planet::Planet() //:QGraphicsEllipseItem(QRect(0,0,0,0))
    2. {
    3. setBrush(QBrush(QColor(45,21,182)));
    4. setPen(QPen(QColor(200,10,10)));
    5. }
    To copy to clipboard, switch view to plain text mode 
    I get different colors, but it doesn't change the Brush if I add
    Qt Code:
    1. setBrush(QBrush(QColor(rand()%255,rand()%255,rand()%255)));
    To copy to clipboard, switch view to plain text mode 

    to the
    Qt Code:
    1. void Planet::paint(QPainter* painter, QStyleOptionGraphicsItem* option,QWidget* widget)
    To copy to clipboard, switch view to plain text mode 
    function.
    Strange.

Similar Threads

  1. how to embed an existing kde program into Konquerer
    By sephiroth_0 in forum KDE Forum
    Replies: 1
    Last Post: 15th August 2006, 12:21
  2. Release my simple program to other users ?
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 9th July 2006, 23:42
  3. why does qt program meet segmentation fault?
    By wquanw in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 15th May 2006, 16:52
  4. preparing program for release
    By impeteperry in forum Installation and Deployment
    Replies: 5
    Last Post: 22nd April 2006, 19:30
  5. Enter key causing program to exit
    By welby in forum Qt Programming
    Replies: 2
    Last Post: 9th March 2006, 16:11

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.