小编meh*_*tfa的帖子

QGraphicsScene::clear 不会改变 sceneRect

我有一个 QGraphicsScene“场景”和 QGraphicsView“graphicsView”。

我有一个画图的方法。当我需要重绘所有图形时,我调用这个方法。一切都好。但我意识到 scene->clear() 不会改变 sceneRect。

我也尝试过:

graphicsView->items().clear();
scene->clear();
graphicsView->viewport()->update();
Run Code Online (Sandbox Code Playgroud)

之后,如果我通过以下方式获取 sceneRect

QRectF bound = scene->sceneRect();
qDebug() << bound.width();
qDebug() << bound.height();
Run Code Online (Sandbox Code Playgroud)

我希望bound.width和bound.height为“0”。但他们不是。我每次都会看到以前的值。当我清除场景本身时如何清除 sceneRect?

使用 GraphicsView->fitInView() 方法时,场景矩形保持不变会带来一些问题。我使用以下代码:

QRectF bounds = scene->sceneRect();
bounds.setWidth(bounds.width()*1.007);          // to give some margins
bounds.setHeight(bounds.height());              // same as above
graphicsView->fitInView(bounds);
Run Code Online (Sandbox Code Playgroud)

虽然我完全清除了场景并只添加了一个相当小的矩形,但由于 sceneRect 仍然太大,所以该矩形不适合视图。

我希望我能解释我的问题。

c++ qt qgraphicsview qgraphicsscene

5
推荐指数
1
解决办法
1723
查看次数

i2cset 16位寄存器地址

我有一个设备通过 i2c 协议进行通信。设备的寄存器地址是16位,但Linux i2c-tools仅支持8位地址。但我找到了一些东西来处理它。

例如,要读取地址为0x0006的寄存器,我使用以下方法:(假设为busId0并且设备i2c地址为0x48)

i2cset -y 0 0x48 0x00 0x06 # this command sets the register address to 0x0006
i2cget -y 0 0x48 # this command the value 0xBA which is true
Run Code Online (Sandbox Code Playgroud)

当我再次调用该i2cget -y 0 0x48命令时,它返回下一个地址处的值。

写入操作按我的预期进行。但是当我尝试写入同一个寄存器时,我失败了。我尝试以下命令:

i2cset -y 0 0x48 0x00 0x06 0xBA 0x0B i
Run Code Online (Sandbox Code Playgroud)

此命令不会返回错误。但是当我再次读取寄存器时,我看到寄存器没有变化。

我使用的设备是AP0100CS。寄存器地址可写。我不知道 i2cset 有什么问题。

linux i2c

5
推荐指数
0
解决办法
4259
查看次数

标签 统计

c++ ×1

i2c ×1

linux ×1

qgraphicsscene ×1

qgraphicsview ×1

qt ×1