- if (rectInView.isNull())
- return;
- QPainterPath clippath;
- clippath.addRect(rectInView);
- QRectF br = rect();
- QPainterPath roundRectPathUpper, roundRectPathLower;
- double roundingY = 20;
- double roundingX = 20;
- double offset = 1;
- painter->setClipRect(option->exposedRect);
- if (roundingX > br.width() / 2) roundingX = br.width() / 2;
-
- int br_endx = (int)(br.x() + br .width() - offset);
- int br_startx = (int)(br.x() + offset);
- int br_starty = (int)(br.y());
- int br_halfy = (int)(br.y() + br.height() / 2 - offset);
- int br_endy = (int)(br.y() + br.height());
-
-
- // build path around clip
- roundRectPathUpper.moveTo(br_endx , br_halfy);
- roundRectPathUpper.arcTo(br_endx - roundingX , br_starty , roundingX, roundingY, 0.0, 90.0);
- roundRectPathUpper.lineTo(br_startx + roundingX , br_starty);
- roundRectPathUpper.arcTo(br_startx , br_starty , roundingX, roundingY, 90.0, 90.0);
- roundRectPathUpper.lineTo(br_startx, br_halfy);
-
- roundRectPathLower.moveTo(br_startx , br_halfy);
- roundRectPathLower.arcTo(br_startx , br_endy - roundingY , roundingX, roundingY, 180.0, 90.0);
- roundRectPathLower.lineTo(br_endx - roundingX , br_endy);
- roundRectPathLower.arcTo(br_endx - roundingX , br_endy - roundingY, roundingX, roundingY, 270.0, 90.0);
- roundRectPathLower.lineTo(br_endx , br_halfy);
-
- QPainterPath resultClipPath = roundRectPathUpper.united(roundRectPathLower);
-
- painter->setClipPath(resultClipPath.intersected(clippath), Qt::IntersectClip);
- //painter->fillPath(roundRectPath, brush()); //, QBrush(QColor(Qt::red)));
- painter->fillRect(br.intersected(rectInView), QBrush(QColor(200, 200, 0, 160)));
- painter->setClipRect(option->exposedRect);
- painter->drawPath(resultClipPath.intersected(clippath));