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. Custom arc borders on QWidget paint event

Custom arc borders on QWidget paint event

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 270 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.
  • K Offline
    K Offline
    Kattia
    wrote on last edited by
    #1

    How to create a QWidget that looks the same as the image below?

    testbg.png

    I mean, the widget should have just these kinds of borders, I don't even know how to start it on the QPaintEvent...
    i mean how to calculate this ? this looks almost impossible to me, please any help

    class Widget : public QWidget
    {
        Q_OBJECT
    public:
    
        Widget() 
        {
            setStyleSheet("background-color: transparent");
            setAttribute(Qt::WA_TranslucentBackground);
            setWindowFlags(Qt::FramelessWindowHint);
        };
    
    
        void paintEvent(QPaintEvent* event) override
        {
            QPainter painter(this);
            painter.setRenderHint(QPainter::Antialiasing);        
    
            const int borderWidth = 10;
            const int cornerRadius = 20;
            const QColor borderColor(255, 0, 0);
    
            QPainterPath path;
        }
    };
    
    int main(int argc, char* argv[])
    {
       QApplication a(argc, argv);
       Widget* w = new Widget;
       w->show();
       return a.exec();
    }
    
    M 1 Reply Last reply
    0
    • K Kattia

      How to create a QWidget that looks the same as the image below?

      testbg.png

      I mean, the widget should have just these kinds of borders, I don't even know how to start it on the QPaintEvent...
      i mean how to calculate this ? this looks almost impossible to me, please any help

      class Widget : public QWidget
      {
          Q_OBJECT
      public:
      
          Widget() 
          {
              setStyleSheet("background-color: transparent");
              setAttribute(Qt::WA_TranslucentBackground);
              setWindowFlags(Qt::FramelessWindowHint);
          };
      
      
          void paintEvent(QPaintEvent* event) override
          {
              QPainter painter(this);
              painter.setRenderHint(QPainter::Antialiasing);        
      
              const int borderWidth = 10;
              const int cornerRadius = 20;
              const QColor borderColor(255, 0, 0);
      
              QPainterPath path;
          }
      };
      
      int main(int argc, char* argv[])
      {
         QApplication a(argc, argv);
         Widget* w = new Widget;
         w->show();
         return a.exec();
      }
      
      M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #2

      @Kattia
      You can subtract two paths with

      QPainterPath subtracted(const QPainterPath &p) const
      
      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