- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我被场景中的简单属性动画的属性卡住了。该项目只需要移动一段距离。有了属性“pos”,它就会移动。对于我的属性“ScenePosition”,它不起作用。调试器进入函数 setScenePosition() 但它对显示的场景没有影响。
// chip.h
class Chip : public QObject, public QGraphicsEllipseItem
{
Q_OBJECT
//THIS WORKS - But i have to use scenePosition instead because of the scene
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
// MY ATTEMPT
Q_PROPERTY(QPointF ScenePosition READ ScenePosition WRITE setScenePosition)
public:
explicit Chip(int x, int y, int w, int h, QObject *parent=NULL);
void setScenePosition(QPointF p);
QPointF ScenePosition();
};
我想我以错误的方式使用了 scenePos()。
//chip.cpp
void Chip::setScenePosition(QPointF p)
{
this->scenePos().setX(p.x());
this->scenePos().setY(p.y());
}
终于是动画的调用了。这个电话似乎没问题,因为它适用于new QPropertyAnimation(item, "pos") 但没有使用 "ScenePosition",这让我对 setter 的实现产生了怀疑。
item = new Chip(col*wCol, 100, wCol, wCol);
item->setVisible(true);
QPropertyAnimation *animation = new QPropertyAnimation(item, "ScenePosition");
addItem(item);
animation->setDuration(1000);
animation->setEndValue( QPoint(col*wCol, 400 - wCol*stacked) );
animation->setEasingCurve(QEasingCurve::OutElastic);
animation->start();
最佳答案
this->scenePos()
返回 QPointF
。使用 this->scenePos().setX(p.x());
只会影响临时的 QPointF
对象,显然不会影响项目位置。您需要使用类似 this->setScenePos(p);
的东西。但是,没有这样的方法。如果该项没有父项,this->setPos(p)
将等效地工作。如果项目有一个父项目,你可以使用this->setPos(this->parentItem()->mapfromScene(p));
。 mapFromScene
会将 p
从场景坐标转换为父项坐标系,子项使用父项坐标系定位,因此它应该可以正常工作。
关于c++ - Qt中scenePos的QPropertyAnimation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21047040/
我正在尝试在 Qt 桌面应用程序中测试动画。我刚刚从帮助中复制了示例。单击按钮后,新按钮仅出现在左上角,没有动画(甚至结束位置也是错误的)。我错过了什么吗? Qt 5.0.1、Linux Mint 6
我正在设置一个新的桌面小部件,以使我的工作生活更轻松,并使用 QPropertyAnimation 使其变得漂亮。淡入淡出应用程序似乎不想起作用,并且以典型的编码方式,它使我的进度陷入停滞。 我正在个
我想让许多彩色点在背景上不断移动。 (下面的代码说明):PolkaDot 小部件是用随机颜色、大小、位置和持续时间构建的。 QPropertyAnimation 在屏幕上从左到右移动小部件,并在动画结
我的动画在这个 QPushButton 上没有按照我预期的方式工作。 这是我的 mainwindow.cpp,因为您在这里看不到任何特别奇怪的地方。在运行时,该按钮如人们所期望的那样出现。我没有任何特
我正在尝试使用多个 QPropertyAnimation 向上移动一个小部件,然后向右移动。 代码如下: QPropertyAnimation* animationUp; QPropertyAnima
这是我的代码: void Widget::update() { if (a==1) { QPushButton button("Animated Button");
我正在尝试使用 Qt 的动画框架。我正在使用 Qt 网站上的一些示例代码,但它无法正常工作,错误:setGeometryDp: 无法在 QWidgetWindow/'QPushButtonClassW
下面的代码没有按预期为按钮设置动画。但如果按钮是独立的并且在它是子部件时停止工作,它会起作用。我在这里做错了什么? 我正在 Ubuntu 上尝试这个。 class TestWindow(QtGui.Q
我正在学习 Qt,认为动画按钮很重要。我正在尝试创建我的自定义 QPushButton 类,它重新实现鼠标进入和离开事件并使用 qt 动画框架。 QPropertyAnimation QPropert
Qt 4.6+ 中的新动画框架基于具有“void setUpdateInterval(int interval)”公共(public)函数的 QTimeLine。基于 QTimeLine,QGraph
我有以下问题:我想使用 QPropertyAnimation 调整窗口大小,以便看起来不错,但是在调整大小时窗口也会立即移动,虽然我不想这样做,但我只想调整窗口大小和不改变其位置值。 所以,这是我的代
我试图在按下按钮时生成动画,但在 self.frame2 返回到大小 0 后它不起作用: 这是一个例子: 帧返回0后,动画不再执行: from PyQt5.QtWidgets import QMain
尝试使用 PyQt5 并使用 QPropertyAnimation 对一条从无到有 (0,0) 到 (200, 200) 的线进行动画处理。我已经阅读了大量有关 Qt 的文档并尝试了几个示例,但我就是
根据以下代码片段,我对QPropertyAnimation 和QParallelAnimationGroup 有疑问: // Create the opacity animation QPropert
我面临一个非常严重的情况。通过写这个问题,我希望真正的专业人士对我将要描述的问题发表意见。我在 https://bugreports.qt.io/ 中报告了一个错误: I have created Q
问题是当我调用QPropertyAnimation.start()时,什么也没发生。 颜色是我要设置动画的属性,按钮是类。 class Button(QPushButton): def __i
请参阅下面的代码。我有一个启动动画的按钮。问题是我只在按下第二个按钮后才看到动画。但是当动画开始时,我注意到它实际上从第一次按下按钮开始就开始了,因为它从一个时刻开始 = [第 1 次和第 2 次按钮
我创建了一个 QRect 对象 QRect ellipse(10.0 , 10.0 , 10.0 , 10.0); QPainter painter(this); painter.setBrush(Q
1。简介 我在 Windows 10 上使用 Python 3.7 并使用 PyQt5 作为 GUI。在我的应用程序中,我得到了一个 QScrollArea()里面有一排按钮。单击时,按钮必须移出该区
我想在 2 秒的时间内逐渐降低 QPushButton 的不透明度以完全透明。为此,我使用了 QPropertyAnimation 类并使用按钮的属性“windowOpacity”来实现效果。但这仅适
我是一名优秀的程序员,十分优秀!