Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Not able to create 3 similar Triangle object
Forum Updated to NodeBB v4.3 + New Features

Not able to create 3 similar Triangle object

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 1.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alvinNew
    wrote on last edited by alvinNew
    #1

    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);
        renderArea->setShape(shape);
    
        Layout_page2->addWidget(renderArea);
    
    p3c0P 1 Reply Last reply
    0
    • A alvinNew

      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);
          renderArea->setShape(shape);
      
          Layout_page2->addWidget(renderArea);
      
      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @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);

      157

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alvinNew
        wrote on last edited by alvinNew
        #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?


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

        p3c0P 1 Reply Last reply
        0
        • A alvinNew

          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?


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

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by p3c0
          #4

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

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

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

          //dialog.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.
          ui->horizontalLayout->addWidget(a);
          ui->horizontalLayout->addWidget(b);
          ui->horizontalLayout->addWidget(c);
          

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

          157

          1 Reply Last reply
          0
          • A Offline
            A Offline
            alvinNew
            wrote on last edited by
            #5

            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();
            
            Layout_page2->addWidget(page2_line);
            Layout_page2->addWidget(widget);
            Layout_page2->addLayout(WordLayout);
            Layout_page2->addWidget(gifmoving);
            
            p3c0P 1 Reply Last reply
            0
            • A alvinNew

              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();
              
              Layout_page2->addWidget(page2_line);
              Layout_page2->addWidget(widget);
              Layout_page2->addLayout(WordLayout);
              Layout_page2->addWidget(gifmoving);
              
              p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

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

              157

              A 1 Reply Last reply
              0
              • p3c0P p3c0

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

                A Offline
                A Offline
                alvinNew
                wrote on last edited by alvinNew
                #7

                @p3c0
                in picpaste
                http://picpaste.com/picpaste-bazEpaOE.jpg

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

                p3c0P 1 Reply Last reply
                0
                • A alvinNew

                  @p3c0
                  in picpaste
                  http://picpaste.com/picpaste-bazEpaOE.jpg

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

                  p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #8

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

                  157

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved