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 a rect with only the bottom left border rounded?

How to draw a rect with only the bottom left border rounded?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 645 Views 1 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.
  • Y Offline
    Y Offline
    Ylvy
    wrote on last edited by
    #1

    How i could draw a rounded rect where only its bottom-left border has a radius of 8px?

    My attempt resulted in this weird thing:
    eef5cd16-f91e-4ce4-bd57-e1bba45cf21a-image.png

    I'm trying to achieve something like this (without stylesheet)
    23d4234d-9d87-4ead-889d-eb828544b18a-image.png

    class Widget : public QWidget
    {
    public:
        Widget(QWidget* parent) : QWidget(parent) {};
    protected:
    
        void paintEvent(QPaintEvent *event) override 
        {
            QPainter painter(this);
            painter.setRenderHint(QPainter::Antialiasing, true);
    
            QRect rect(100, 100, 300, 100);
            QPainterPath path;
            path.moveTo(rect.left(), rect.top());
    
            path.lineTo(rect.right(), rect.top());
            path.lineTo(rect.right(), rect.bottom());
            path.lineTo(rect.left() + 8, rect.bottom());
            path.arcTo(QRectF(rect.bottomLeft() - QPointF(0, 8), QSizeF(16, 16)), 90, 90);
            path.lineTo(rect.left(), rect.top());
    
            painter.setPen(Qt::red);
            painter.setBrush(Qt::black);
            painter.drawPath(path);
        }
    };
    
    M 1 Reply Last reply
    0
    • Y Offline
      Y Offline
      Ylvy
      wrote on last edited by Ylvy
      #3

      I got it working, only the bottom left corner rounded:

      path.moveTo(mrect.bottomLeft() + QPointF(borderRadius, 0));
      path.lineTo(mrect.bottomRight());
      path.lineTo(mrect.topRight());
      path.lineTo(mrect.topLeft());
      path.lineTo(mrect.bottomLeft() + QPointF(0, -borderRadius));
      path.quadTo(mrect.bottomLeft(), mrect.bottomLeft() + QPointF(borderRadius, 0));
      
      1 Reply Last reply
      1
      • Y Ylvy

        How i could draw a rounded rect where only its bottom-left border has a radius of 8px?

        My attempt resulted in this weird thing:
        eef5cd16-f91e-4ce4-bd57-e1bba45cf21a-image.png

        I'm trying to achieve something like this (without stylesheet)
        23d4234d-9d87-4ead-889d-eb828544b18a-image.png

        class Widget : public QWidget
        {
        public:
            Widget(QWidget* parent) : QWidget(parent) {};
        protected:
        
            void paintEvent(QPaintEvent *event) override 
            {
                QPainter painter(this);
                painter.setRenderHint(QPainter::Antialiasing, true);
        
                QRect rect(100, 100, 300, 100);
                QPainterPath path;
                path.moveTo(rect.left(), rect.top());
        
                path.lineTo(rect.right(), rect.top());
                path.lineTo(rect.right(), rect.bottom());
                path.lineTo(rect.left() + 8, rect.bottom());
                path.arcTo(QRectF(rect.bottomLeft() - QPointF(0, 8), QSizeF(16, 16)), 90, 90);
                path.lineTo(rect.left(), rect.top());
        
                painter.setPen(Qt::red);
                painter.setBrush(Qt::black);
                painter.drawPath(path);
            }
        };
        
        M Offline
        M Offline
        mpergand
        wrote on last edited by mpergand
        #2

        @Ylvy
        try for angles (not tested)
        -45, -225

        path.moveTo(rect.left(), rect.top());
        path.lineTo(rect.right(), rect.top());
        path.lineTo(rect.right(), rect.bottom());
        path.lineTo(rect.left() +16, rect.bottom());
        path.arcTo(QRectF(rect.bottomLeft() +QPoint(0,-16), QSizeF(16,16)), -90,-90);
        path.lineTo(rect.left(), rect.top());
        
        1 Reply Last reply
        0
        • Y Offline
          Y Offline
          Ylvy
          wrote on last edited by Ylvy
          #3

          I got it working, only the bottom left corner rounded:

          path.moveTo(mrect.bottomLeft() + QPointF(borderRadius, 0));
          path.lineTo(mrect.bottomRight());
          path.lineTo(mrect.topRight());
          path.lineTo(mrect.topLeft());
          path.lineTo(mrect.bottomLeft() + QPointF(0, -borderRadius));
          path.quadTo(mrect.bottomLeft(), mrect.bottomLeft() + QPointF(borderRadius, 0));
          
          1 Reply Last reply
          1
          • Y Ylvy has marked this topic as solved on

          • Login

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