Qt cpp QPainter 在窗口点位 x,y 绘制两个同心圆,中心的同心圆为实心,外围的为空心。外围圆在上下左右加上10px的线段
时间: 2024-02-18 09:00:53 浏览: 161
![7Z](https://csdnimg.cn/release/download/static_files/pc/images/minetype/7Z.png)
利用QPainter绘制各种图形
![star](https://csdnimg.cn/release/wenkucmsfe/public/img/star.98a08eaa.png)
可以使用QPainter在窗口的指定点位x、y处绘制两个同心圆,其中中心的同心圆为实心,外围的为空心,并在外围圆上下左右加上10px的线段。
以下是示例代码:
```cpp
void MyWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true); // 抗锯齿
int x = 100; // 指定点位x
int y = 100; // 指定点位y
// 绘制中心的实心圆
painter.setBrush(Qt::red);
painter.drawEllipse(x - 50, y - 50, 100, 100);
// 绘制外围的空心圆
painter.setBrush(Qt::NoBrush);
painter.setPen(QPen(Qt::red, 10));
painter.drawEllipse(x - 70, y - 70, 140, 140);
// 绘制上下左右的线段
painter.setPen(QPen(Qt::red, 10));
painter.drawLine(x, y - 70, x, y - 80); // 上
painter.drawLine(x, y + 70, x, y + 80); // 下
painter.drawLine(x - 70, y, x - 80, y); // 左
painter.drawLine(x + 70, y, x + 80, y); // 右
}
```
在该示例中,我们使用QPainter在指定点位x、y处绘制了两个同心圆,其中中心的同心圆使用红色实心填充,外围的同心圆则不填充(即为空心),使用红色边框线条,并且线条宽度为10px。我们还在外围圆的上下左右各绘制了一条10px宽的红色线段,以满足您的需求。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)