gpt4 book ai didi

c++ - 如何处理QPainter的边界矩形单击

转载 作者:行者123 更新时间:2023-12-03 07:21:45 24 4
gpt4 key购买 nike

enter image description here
现在,我使用QPainterPath绘制我的自定义窗口小部件并旋转技术,此处列出了代码段:

QRectF flowerBanRect(-radius + (-width / 2), -radius + (-margin) + (-height), width, height);
QPainterPath flowerPath;
flowerPath.moveTo(-radius + (-width / 4), -diameter + (-margin));
flowerPath.lineTo(-radius + width / 4, -diameter + (-margin));
flowerPath.lineTo(-radius + width / 2, -diameter + (-margin) + (-height));
flowerPath.lineTo(-radius + (-width / 2), -diameter + (-margin) + (-height));

QPainterPath diffPath = flowerPath - headPath;

painter->setBrush(QBrush(getReagentSeatColor(0)));
painter->fillPath(diffPath, QBrush(getReagentSeatColor(0)));
painter->drawText(flowerBanRect, Qt::AlignHCenter | Qt::AlignTop, QString("01"));
painter->save();

float degree = 360.0 / MAX_TRAY;
for (int i = 0; i < MAX_TRAY - 1; ++i) {
painter->rotate(degree);
painter->setBrush(QBrush(getReagentSeatColor(i + 1)));
painter->fillPath(diffPath, QBrush(getReagentSeatColor(i + 1)));
painter->drawText(flowerBanRect, Qt::AlignHCenter | Qt::AlignTop, QString("%1").arg(i + 2, 2, 10, QChar('0')));
}
但是现在,我如何处理 每隔单击。

最佳答案

最好的方法是像这样在类中重写QWidget的mousePressEvent。

void mousePressEvent(QMouseEvent *event) override;
然后,您调用想要从 QMouseEvent doc获取位置的任何函数,但我建议您使用event-> pos(),因为它会返回相对于您从中调用它的小部件的位置。您可以在运行时计算每个扇区的位置,也可以将它们存储在QList或QMap中。然后比较位置并找出鼠标所在的扇区。

关于c++ - 如何处理QPainter的边界矩形单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64888469/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com