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. How to draw rounded live using QT
Forum Updated to NodeBB v4.3 + New Features

How to draw rounded live using QT

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 2.2k 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.
  • C Offline
    C Offline
    CorD SaC
    wrote on last edited by
    #1

    How can I design rounded line like this image.I need to design a rounded line when the button click.

    void MainWindow::on_btnCreateRoundedLine_clicked()
    {
    
    }
    

    alt text

    K 1 Reply Last reply
    0
    • C CorD SaC

      How can I design rounded line like this image.I need to design a rounded line when the button click.

      void MainWindow::on_btnCreateRoundedLine_clicked()
      {
      
      }
      

      alt text

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @CorD-SaC

      Possibly as part of an ellipse

      Vote the answer(s) that helped you to solve your issue(s)

      C 1 Reply Last reply
      2
      • K koahnig

        @CorD-SaC

        Possibly as part of an ellipse

        C Offline
        C Offline
        CorD SaC
        wrote on last edited by
        #3

        @koahnig Can you provide me sample code please

        mrjjM 1 Reply Last reply
        0
        • C CorD SaC

          @koahnig Can you provide me sample code please

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @CorD-SaC
          Can you provide at little bit more information ?
          Are you using QGraphicsView or QPainter ?
          Where do you want to draw it ?
          You cannot just paint in on_btnCreateRoundedLine_clicked
          as all painting must be done in paintEvent function.
          You could paint on a pixmap and use a QLabel to display it.

          Also what you are showing is not really a line with round edge but
          more of a spline type.

          A very fast way would be to use drawing program like inkscape and simply load
          it as a SVG image into a QLabel.
          alt text

          But it all really depends on what you are trying to do.

          C 1 Reply Last reply
          2
          • mrjjM mrjj

            @CorD-SaC
            Can you provide at little bit more information ?
            Are you using QGraphicsView or QPainter ?
            Where do you want to draw it ?
            You cannot just paint in on_btnCreateRoundedLine_clicked
            as all painting must be done in paintEvent function.
            You could paint on a pixmap and use a QLabel to display it.

            Also what you are showing is not really a line with round edge but
            more of a spline type.

            A very fast way would be to use drawing program like inkscape and simply load
            it as a SVG image into a QLabel.
            alt text

            But it all really depends on what you are trying to do.

            C Offline
            C Offline
            CorD SaC
            wrote on last edited by CorD SaC
            #5

            @mrjj I tried it like this problem solved.now I need to change the color of this shape when I select color from color dialog or another way,and also I need to rotate this Item.how can I do this?

            This is my code.

            void Widget::on_pushButton_clicked()
            {
                QPainterPath path;
                path.moveTo(10, 20);
                path.lineTo(10, 40);
                path.arcTo(QRectF(10, 20, 40, 40), 180, 180);
                path.moveTo(50, 40);
                path.lineTo(50, 20);
                QPen redPen(Qt::red);
                redPen.setWidth(2);
                QGraphicsPathItem* item = ui->graphicsView->scene()->addPath(path, redPen);
                /*
                    QGraphicsPathItem* item = new QGraphicsPathItem(path);
                    item->setPen(redPen);
                */
            
                item->setFlag(QGraphicsItem::ItemIsMovable, true);
                item->setFlag(QGraphicsItem::ItemIsSelectable,true);
            }
            
            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6
              • now I need to change the color of this shape

              You can just do it
              http://doc.qt.io/qt-5/qabstractgraphicsshapeitem.html#setPen

              1 Reply Last reply
              2
              • C Offline
                C Offline
                CorD SaC
                wrote on last edited by
                #7

                @mrjj said in How to draw rounded live using QT:

                can just do it

                I solved rotate item problem. now I need to change color of this item.according to your answer I already use setPen method. But how can I change the color of this Item when I select color from color dialog.

                K 1 Reply Last reply
                0
                • C CorD SaC

                  @mrjj said in How to draw rounded live using QT:

                  can just do it

                  I solved rotate item problem. now I need to change color of this item.according to your answer I already use setPen method. But how can I change the color of this Item when I select color from color dialog.

                  K Offline
                  K Offline
                  koahnig
                  wrote on last edited by
                  #8

                  @CorD-SaC

                  How about this method setColor?

                  Vote the answer(s) that helped you to solve your issue(s)

                  C 1 Reply Last reply
                  2
                  • K koahnig

                    @CorD-SaC

                    How about this method setColor?

                    C Offline
                    C Offline
                    CorD SaC
                    wrote on last edited by
                    #9

                    @koahnig Can You give some sample code.How can I pick color from QColorDialog and assign that color to this curve shape

                    K 1 Reply Last reply
                    0
                    • C CorD SaC

                      @koahnig Can You give some sample code.How can I pick color from QColorDialog and assign that color to this curve shape

                      K Offline
                      K Offline
                      koahnig
                      wrote on last edited by
                      #10

                      @CorD-SaC

                      There is this example in the document database

                      Vote the answer(s) that helped you to solve your issue(s)

                      1 Reply Last reply
                      2

                      • Login

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