获取QPainter的可见区域 [英] Get visible area of QPainter
问题描述
我在 QScrollArea
内有一个自绘的 QWidget
,所以在绘画时,可见的部件。要这样做,我需要有 QPainter
的可见区域的矩形。
I have an owner-drawn QWidget
inside a QScrollArea
, so when painting, and I want to paint only the parts that are visible. To do so, I need to have the rectangle of the visible area of the QPainter
.
QPainter :: viewport()
, QPainter :: window()
和 QPainter :: clipBoundingRect()
,所以我把这个代码记录他们的输出:
The only candidates were QPainter::viewport()
, QPainter::window()
, and QPainter::clipBoundingRect()
, so I put this code to log their output:
setMinimumHeight(3000);
setMinimumWidth(3000);
}
void MyWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
qDebug() << painter.viewport() << painter.window() << painter.clipBoundingRect();
然后我移动水平和垂直滚动条,但记录的输出很奇怪:
Then I moved the horizontal and vertical scrollbars, but the logged output was strange:
QRect(0,0 3000x3000) QRect(0,0 3000x3000) QRectF(-21,-21 0x0)
QRect(0,0 3000x3000) QRect(0,0 3000x3000) QRectF(-1,-21 0x0)
QRect(0,0 3000x3000) QRect(0,0 3000x3000) QRectF(-1,-1 0x0)
因为,你可以看到,这些函数都没有给出实际的可见区域, >
As, you can see, none of these functions give the actual visible area, how do I get it?
推荐答案
我会尝试这样:
...
setMinimumHeight(3000);
setMinimumWidth(3000);
}
void MyWidget::paintEvent(QPaintEvent *paintEvent)
{
qDebug() << paintEvent.rect();
...
请参阅文档。
这篇关于获取QPainter的可见区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!