boundingRect调用问题

Oskar_Sun 2015-01-19 10:48:03
想在boundingRect内画一图形,然后鼠标拖动改变大小位置等。需要boungdingRect随着图形的大小改变而改变。
#include "rectitem.h"
#include<QPainter>
#include<QGraphicsSceneMouseEvent>
#include<QDebug>

RectItem::RectItem()
{
rect.setRect(-50,-50,100,100);
}

QRectF RectItem::boundingRect()const
{
qreal penWidth=1;
return QRectF(rect.adjusted(-penWidth,-penWidth,penWidth,penWidth));
}
void RectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->drawRect(rect);
}
void RectItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
rect.setBottom(event->pos().y());
qDebug()<<"1";
update();
}

其中boundingRect想通过adjusted函数随着我的rect的改变而改变,但实际中出现如下图问题:

问题描述:当鼠标在rect内点击的时候rect确实改变了大小,但原来的rect底边没有刷新掉。但是拖动widget改变窗口大小或者按键盘上的某些按键也会让没刷掉的边消失。这是什么原因?怎么解决?
...全文
661 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Oskar_Sun 2015-01-19
  • 打赏
  • 举报
回复
引用 2 楼 dbzhang800 的回复:
多看看Manual即可解决这个问题 QRectF QGraphicsItem::boundingRect() const [pure virtual] If you want to change the item's bounding rectangle, you must first call prepareGeometryChange(). This notifies the scene of the imminent change, so that it can update its item geometry index; otherwise, the scene will be unaware of the item's new geometry, and the results are undefined (typically, rendering artifacts are left within the view).
问题解决了,低级的错误,让您见笑了。 不过还有一个问题是,当我把矩形rect右边的边线拖动到左边的时候(就是类似于把矩形翻转,让右边变成左边,左边变成右边)又会出现这样无法更新的问题。这是因为什么呢?
dbzhang800 2015-01-19
  • 打赏
  • 举报
回复
多看看Manual即可解决这个问题 QRectF QGraphicsItem::boundingRect() const [pure virtual] If you want to change the item's bounding rectangle, you must first call prepareGeometryChange(). This notifies the scene of the imminent change, so that it can update its item geometry index; otherwise, the scene will be unaware of the item's new geometry, and the results are undefined (typically, rendering artifacts are left within the view).
Oskar_Sun 2015-01-19
  • 打赏
  • 举报
回复
个人分析应该是boundingRect在rect改变后没有及时调用返回新的QRectF,但是boundingRect不是QGraphicsView调用的么,那鼠标的点击或松开就应该调用到boundingRect啊。 还是说boundingRect已经返回新的边框,但Widget中没有刷新?
内容概要:SSD2828QN4是一款MIPI主桥接芯片,用于连接应用处理器与传统并行LCD接口及支持MIPI从属接口的LCD驱动器。该芯片支持最高每通道1Gbps的串行链路速度,最多可配置4个数据通道,显著减少了信号数量。它支持多种接口模式,包括RGB+SPI组合接口,适用于驱动智能或非智能显示面板,并能通过命令模式和视频模式传输数据。芯片内置时钟和复位模块、外部接口、协议控制单元(PCU)、包处理单元(PPU)、错误校正码/循环冗余校验(ECC/CRC)模块、长包和命令缓冲区、D-PHY控制器、模拟收发器以及内部锁相环(PLL),确保了高效的数据传输和系统稳定性。此外,文档详细描述了芯片的引脚分配、寄存器设置、操作模式、电源序列、时序特性等关键参数,为开发者提供了全面的技术指导。 适合人群:具备一定硬件设计基础,从事嵌入式系统开发、显示技术研究的研发人员。 使用场景及目标:①实现应用处理器与MIPI兼容显示屏之间的高速数据传输;②优化显示系统的功耗表现,减少电磁干扰(EMI);③通过灵活配置不同接口模式来适应各种显示设备的需求。 阅读建议:此文档面向具有一定电子工程背景的专业人士,建议读者结合实际项目需求深入理解各章节内容,特别是关于寄存器配置、时序要求等方面的具体说明。对于初次接触此类技术的开发者而言,建议先熟悉基本概念再逐步掌握高级功能的应用方法。

21,498

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧