我在现有应用程序中使用QCustomPlot库(基于QWidget的绘图库),该应用程序主要由 QDeclarativeView
UI组成 .
我从 QGraphicsProxyWidget
派生了一个QmlPlot类,我通过插件向Qml公开,然后我用setWidget()方法插入QCustomPlot Widget .
这非常好用,我可以在qml中实现它 .
Item {
id: plotAnchor
anchors.top: iMainCourbe.top
anchors.bottom: iMainCourbe.bottom
anchors.left: iMainCourbe.left
anchors.right: iMainCourbe.right
QmlPlot {
id: qcpproxy
anchors.fill: plotAnchor
//otherstuff
rootScale: automate.scale
}
Rectangle {
id: borders
anchors.fill: plotAnchor
color: "transparent"
border.color: "red"
border.width: 2
}
}
这是包含其他几个子组件的更大组件的一部分 .
这是模拟项目的一部分 . 我们想要模拟数字录音机 . 所有尺寸(和字体大小,边框宽度等)都在所述数字 Logger 的规格中得到很好的定义,因此我决定给根部件固定的高度和宽度对应于数字 Logger 屏幕的分辨率 . 这样我们就可以根据规范设置qml子组件的所有维度,比例是完美的 .
但是,我需要在结尾显示qml组件以进行缩放(1:1),因此使用基于显示屏大小(计算机)及其dpi的一些计算,使用 scale
属性的根项目,达到这个1:1的比例 .
DigitalRecorder.qml
BaseComponent {
id: iMain
width: 320
height: 240
scale: someFunction()
}
这适用于所有基于qml的组件,但对于 QGraphicsProxyWidget
,它看起来非常像素化 . 根据我从调试器中收集的内容,QPixmap缓冲区大小不会缩放,也不是窗口小部件的视口 . Widget继续绘制在相同的小表面上,然后结果由Qml缩放(不良) .
What I have tried :
我忽略了 QGraphicsProxyWidget
上的转换 . 然后我用手动计算的缩放尺寸手动调用 QGraphicsWidget::resize()
,并且在图像质量方面得到了更好的结果,因为QPixmap缓冲区和包含的窗口小部件的视口相应地调整了大小
QmlPlot::QmlPlot(QDeclarativeItem *parent):
QGraphicsProxyWidget(parent),
m_rtplot(NULL)
{
connect(parentItem(), SIGNAL(scaleChanged()), SLOT(rescaleFromQml())); // This cannot work because parentitem() is null here and moreover scaleChanged() isn't emmited byt the children of the root item when the root item is scaled..
setFlag(QGraphicsItem::ItemIgnoresTransformations, true); // this ignores scaling
m_rtplot = new RealTimeCustomPlot();
setWidget(m_rtplot);
setVisible(true);
}
void QmlPlot::rescaleFromQml()
{
resize(parentObject()->sceneBoundingRect().size());
}
必须有一些更好的方法来实现这一点,所以我的问题是:
如何让我的QGraphicsProxyWidget对根项目的缩放做出反应?我应该在什么事情上做出反应?在哪个事件处理程序?
更新1:
我在rescaleFromQml()中编辑了非常有意义的东西 .
重新解释我的整个问题:而不是手动将一些信号连接到我的rescaleFromQml()方法,我应该把它放在哪个事件处理程序中?并对哪个事件做出反应?