Bug? - Moving QFrame - not working when setVisible(false)
-
I have this code that move a QFrame and show it (working) :
@ frameAchievement->setVisible(true);
QPoint currentPoint = frameAchievement->pos();
frameAchievement->setProperty("pos", QPoint(currentPoint.x()-250, currentPoint.y()));
qDebug() << "FRAME IS NOW AT " << frameAchievement->pos();@This one doesn't work (widget position is not moved on screen, allthought it printed the correct coordinate on the log) :
@ QPoint currentPoint = frameAchievement->pos();
frameAchievement->setProperty("pos", QPoint(currentPoint.x()-250, currentPoint.y()));
frameAchievement->setVisible(true);
qDebug() << "FRAME IS NOW AT " << frameAchievement->pos();@I need to set visible my Widget after moving it, or it cause a flashing widget on screen for a brief moment, and I don't want that effect.
So the bug would be, changing the "pos" property is not working when QWidget is not visible.
Thank you
-
Here is the full code for anyone interested, still haven't figured why I can't move my QFrame...
@void WorkoutDialog::animateAchievement() {
achievementCurrentlyPlaying = true; ///Take achievement from top of queue Achievement *achievement = queueAchievement.head(); /// change name and icon (64x64) labelAchievementName->setText(achievement->getName()); labelIcon->setStyleSheet("image: url(" + achievement->getIconPath() + ")"); if (firstTimePlayAchievement) { ///TOFIX: widget flash for a second when first appearing frameAchievement->setVisible(true); QPoint currentPoint = frameAchievement->pos(); frameAchievement->setProperty("pos", QPoint(currentPoint.x()-250, currentPoint.y())); } qDebug() << "FRAME IS NOW AT " << frameAchievement->pos(); QPoint currentPoint = frameAchievement->pos(); QPoint bottomRightBeforeAnim = QPoint(currentPoint.x(), currentPoint.y()); QPoint bottomRightAftereAnim = QPoint(bottomRightBeforeAnim.x()+250, bottomRightBeforeAnim.y()); QPropertyAnimation *animationShow = new QPropertyAnimation(frameAchievement, "pos"); animationShow->setDuration(1500); animationShow->setStartValue(bottomRightBeforeAnim) ; animationShow->setEndValue(bottomRightAftereAnim) ; animationShow->start(QAbstractAnimation::DeleteWhenStopped); firstTimePlayAchievement = false; timerRemoveAnimation->start(5000);
}@
-
How my QFrame is created :
@ //// ---------------------- Test Achievement Window --------------------------
frameAchievement = new QFrame(ui->widget_allSpeedo);
frameAchievement->setAttribute(Qt::WA_TransparentForMouseEvents,true);
frameAchievement->setFocusPolicy(Qt::NoFocus);
frameAchievement->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
frameAchievement->setFixedSize(250, 150);
frameAchievement->setObjectName("frameAchievement");
frameAchievement->setStyleSheet("QFrame#frameAchievement { background-color : rgba(1,1,1,240); "
"border: 4px solid gray; }"
"QLabel { color: white; }");QGridLayout *gridAchievement = new QGridLayout(frameAchievement); QFont fontBold; fontBold.setPointSize(10); fontBold.setBold(true); labelIcon = new QLabel(frameAchievement); labelIcon->setMinimumHeight(64); labelIcon->setMaximumHeight(64); labelIcon->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); labelIcon->setObjectName("labelIcon"); labelIcon->setStyleSheet("image: url(:/image/icon/trophy)"); QLabel *labelAchievementReceived = new QLabel(frameAchievement); labelAchievementReceived->setMinimumHeight(20); labelAchievementReceived->setMaximumHeight(20); labelAchievementReceived->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); labelAchievementReceived->setAlignment(Qt::AlignBottom | Qt::AlignRight); labelAchievementReceived->setAttribute(Qt::WA_TransparentForMouseEvents,true); labelAchievementReceived->setText(tr("New Achievement!")); labelAchievementReceived->setFont(fontBold); labelAchievementName = new QLabel(frameAchievement); labelAchievementName->setMinimumHeight(20); labelAchievementName->setMaximumHeight(20); labelAchievementName->setMaximumWidth(400); labelAchievementName->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); labelAchievementName->setAlignment(Qt::AlignBottom | Qt::AlignRight); labelAchievementName->setAttribute(Qt::WA_TransparentForMouseEvents,true); labelAchievementName->setText(tr("Name here!")); labelAchievementName->setFont(fontBold); gridAchievement->addWidget(labelIcon, 0, 0, 2, 1); gridAchievement->addWidget(labelAchievementReceived, 0, 1); gridAchievement->addWidget(labelAchievementName, 1, 1); QGridLayout *glayout = static_cast<QGridLayout*>( ui->widget_allSpeedo->layout() ); glayout->addWidget(frameAchievement, 0, 0, 0, 0); frameAchievement->setAttribute(Qt::WA_TransparentForMouseEvents,true); timerRemoveAnimation = new QTimer(this); timerAnimationCompleted = new QTimer(this); connect (timerRemoveAnimation, SIGNAL(timeout()), this, SLOT(removeAchievementAnimation()) ); connect (timerAnimationCompleted, SIGNAL(timeout()), this, SLOT(lastAchievementAnimationDone()) ); achievementCurrentlyPlaying = false; firstTimePlayAchievement = true; /// Hide achievement window /// Not working to move position manually here.. // frameAchievement->setVisible(true); // QPoint currentPoint = frameAchievement->pos(); // frameAchievement->setProperty("pos", QPoint(currentPoint.x()-250, currentPoint.y())); frameAchievement->setVisible(false);
@