Results 1 to 1 of 1

Thread: QPainter usage for simple 2D objects.

  1. #1
    Join Date
    Jan 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default QPainter usage for simple 2D objects.

    Hi

    I have an application that reads simple data defining a 2D profile made up of lines and arcs.

    I have all the logic in place in my QT app to allow input/output/modification/validation of this data.

    What I'm having an issue with is creating a 2D display of this profile.

    I've created the Mainwindow of this application in QTDesigner and have added a QGraphicsView. I then have created a QGraphicsScene and set this scene in my QGraphicsView. I then use a QPainterPath to created the profile. The problem is that there isn't a way to create arc segments in a QPainterPath only full circles(ellipses). So I've been researching a different solution...

    I have noticed elsewhere that I can create a QPainter (which has all of the 2D types I require) and add the 2D objects and then use the QGraphicsView Render Public Function to display the objects. However I can't get anything to display....

    I've done lots of research and there is plenty of advice given but none specific to my requirement and I'm stuck.

    I've added the click SLOT that draws the objects. I haven't included the ui file but it only contains a QGraphicsView and a PushButton which when clicked runs the attached code.

    void MainWindow:n_arcButton_clicked()
    {
    QRect viewport = ui->graphicsView->viewport()->rect();
    QPixmap pix(viewport.width(), viewport.height());
    QPainter qp;
    qp.begin(&pix);
    QPen pen(Qt::black);
    pen.setWidth(4);
    qp.setPen(pen);
    qp.drawLine(0,0,10,15);
    qp.drawLine(10,10,20,20);
    qp.end();
    ui->graphicsView->render(&qp);
    }

    Apologies for the code directly in the message.

    Thanks

    Brian
    Attached Files Attached Files

Similar Threads

  1. Fast(est) way of drawing simple objects
    By eperfa in forum Newbie
    Replies: 6
    Last Post: 9th April 2011, 20:24
  2. 3D engine to create simple 3D objects
    By been_1990 in forum General Discussion
    Replies: 11
    Last Post: 15th December 2010, 11:57
  3. Replies: 1
    Last Post: 29th July 2010, 13:35
  4. Memory usage of simple Qt app
    By DiamonDogX in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2009, 06:53
  5. Simple: Operator overloading with heap objects
    By durbrak in forum General Programming
    Replies: 12
    Last Post: 25th April 2007, 13:20

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.