0
私はQTimer(アニメーションシステムなし)とペイントでQtウィジェットをアニメーション化したいので、enterEventとtimercallスロットにタイマーと開始点を入れます。境界線を大きくするなど... しかし、それはちょうど実行されませんそして、コード255を使用してアプリケーションの終了と言う:QtウィジェットをQTimerでアニメートすることに問題があります(コード255で終了)?
の.h
#include <QtWidgets>
class QWidget;
class QPainter;
class QTimer;
class Sample : public QWidget
{
Q_OBJECT
public:
Sample(QWidget *parent = 0);
~Sample();
private:
QTimer *timer;
int weight=1, step=1;
protected:
virtual void paintEvent(QPaintEvent *);
virtual void enterEvent(QEvent *);
public slots:
void timercall();
};
た.cpp、その後
Sample::Sample(QWidget *parent)
: QWidget(parent)
{
connect(timer,SIGNAL(timeout()),this,SLOT(timercall()));
}
Sample::~Sample() {}
void Sample::paintEvent(QPaintEvent *) {
QPainter painter(this);
painter.setPen(QPen(Qt::black,weight));
painter.setRenderHint(QPainter::Antialiasing);
QRect Rectangle=QRect (10,10,width()-20,height()-20);
painter.drawRect(Rectangle);
}
void Sample::enterEvent(QEvent *) {
timer->start(100);
}
void Sample::timercall() {
weight+=1;
if (step > 10) {
timer->stop();
}
step++;
repaint();
}
、私は自分のコードからこの行を削除します。
をconnect(timer,SIGNAL(timeout()),this,SLOT(timercall()));
in enterEventアプリケーションがクラッシュしました。