Not able to create 3 similar Triangle object

  • Took RenderArea class from basicdrawing and insert into my project. Not able to create a sequence of Triangle object

        RenderArea* renderArea;
        renderArea = new RenderArea;
        RenderArea::Shape shape = RenderArea::Shape(4);

  • Moderators

    @alvinNew Looking at source it seems you need to use a polygon which is at index 3 and set points count to 3 in renderarea.cpp here painter.drawPolygon(points, 3);

  • Did few experiment with renderarea class, cannot get it to work. It's alright.
    Any idea, How to create 3 triangle and blind it in horizontal layout?

    | / | / | /
    |/ |/ |/

  • Moderators

    @alvinNew Create a custom widget by subclassing QWidget and override paintEvent to drawing custom shapes. Following is an example:

    Triangle::Triangle(QWidget *parent) :
    void Triangle::paintEvent(QPaintEvent *e)
        static const QPoint points[3] = {
            QPoint(40, 80),
            QPoint(20, 10),
            QPoint(60, 10),
        QPainter p(this);

    and then add it from your main code for eg. from dialog.cpp or mainwindow.cpp

    #include "triangle.h"
    Triangle *a = new Triangle(this);
    Triangle *b = new Triangle(this);
    Triangle *c = new Triangle(this);
    //add it to horizontal or vertical layout, add stretch as required.

    Try playing with the above code. Make it more dynamic by calculating points depending upon the widget size.
    Hope this helps...

  • It works, i got the 3 triangle.
    But when i addwidget with other layout and widget.
    There is a huge spacing(row).
    I want the 3 triangle directly after my page2_line, best it is joined.

    =======mainwindow =======

    PictureWidget *widget = new PictureWidget();

  • Moderators

    @alvinNew How does it look now? Can post post a screenshot ?
    Besides, Layouts are meant for that. They equally space widgets inside them.

  • @p3c0
    in picpaste

    want to add the page2_line in Widget, but i felt logically this isn;t correct

  • Moderators

    @alvinNew Try setting maximum and minimum size to the widget which is above the triangle widget.

Log in to reply