Advertisement
tasuku

Untitled

Mar 24th, 2015
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <QtWidgets>
  2.  
  3. class Widget : public QWidget
  4. {
  5.     Q_OBJECT
  6. public:
  7.     explicit Widget(QWidget *parent = 0)
  8.         : QWidget(parent)
  9.     {
  10.         resize(60, 60);
  11.     }
  12.  
  13. protected:
  14.     void paintEvent(QPaintEvent *e) {
  15.         QPainter p(this);
  16.         p.fillRect(rect(), Qt::red);
  17.         QPainterPath fill;
  18.         fill.addRect(rect());
  19.         QPainterPath excluded;
  20.         excluded.addRect(20, 20, 20, 20);
  21.        
  22.         p.setClipPath(fill.subtracted(excluded));
  23.         p.fillRect(10, 10, 40, 40, Qt::blue);
  24.     }
  25. };
  26.  
  27. int main(int argc, char **argv)
  28. {
  29.     QApplication app(argc, argv);
  30.  
  31.     Widget widget;
  32.     widget.show();
  33.  
  34.     return app.exec();
  35. }
  36.  
  37. #include "main.moc"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement