Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] SIGNAL inherited from parent & Achievement pop up QWidget
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] SIGNAL inherited from parent & Achievement pop up QWidget

Scheduled Pinned Locked Moved General and Desktop
15 Posts 3 Posters 3.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maximus
    wrote on last edited by
    #5

    Thanks guy for your valuable help, I used both your advice! source code updated up here.

    100% working :

    @ManagerAchievement::ManagerAchievement(QObject *parent)
    :QObject(parent) {

    achievement2hours = new AchievementRide2Hours();
    
    connect(achievement2hours, SIGNAL(achievementCompleted()), this, SLOT(receiveAchievement()));
    

    }

    void ManagerAchievement::receiveAchievement() {

    Achievement *achievement = ((Achievement*)sender());
    qDebug() << achievement->getName();
    

    }@


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #6

      Don't use a c-style cast for a QObject, use qobject_cast

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maximus
        wrote on last edited by
        #7

        Thanks, old java habits

        @Achievement *achievement = qobject_cast<Achievement *>(sender());@

        Now to learn how to make nice animation with Qt to show theses achievements :)


        Free Indoor Cycling Software - https://maximumtrainer.com

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #8

          QWidget ? QGraphicsView ? QML ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maximus
            wrote on last edited by
            #9

            All options are opens, I would just put a simple box popup in the center of a QDialog with some effect on it, any recommendation ? I'm using Qt 5.2.1 going to deploy on mac/win/linux not yet on mobile so I think i'd put QML outside for now.

            Thanks!


            Free Indoor Cycling Software - https://maximumtrainer.com

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #10

              AFAIK, the widgets are also running on mobile but might be less good looking.

              If you go the QML way, you might want to rebuild completely for it rather that have a separate product for mobile.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • X Offline
                X Offline
                Xander84
                wrote on last edited by
                #11

                I was kinda surprised today when I found out the the base animation classes are part of the QtCore module itself (and not QtQuick or something).
                So you might be able to use the animation functions from QML in a widget project, but honestly I've not seen any examples for that anywhere, but it should be possible, if you don't want to use QML or already have a complex widget project and don't want to migrate that. Doing animation in QML is definitely easier and a major part of Qt Quick :)

                Even if you only want to build a desktop application I would still suggest using QML if you start the project fresh, but that is your choice of course. I don't want to do any weird comparisons but if you know Java you might want to compare Qt widgets projects to Java Swing and QML projects to JavaFX (or if you are a .net guy think of WIndows Forms/Qt widgets and WPF/QML), so it is a "complete" replacement for widget based projects. You can also embed a QML widget inside of your widget application if you need to.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  maximus
                  wrote on last edited by
                  #12

                  Thanks guys,

                  I'm pretty new with QML and QtQuick, if I want to use these things, I have to rewrite all source code for my interface correct? I was planning on using standard Qt and hope it works on mobile.. :) I already have too much source code done and i'm using outside libraries, Qwt, etc..

                  I did a standard QWidget that appear at the bottom right corner of the QDialog.
                  I'm trying to do something like Steam achievement (1:49 in" this video)":https://www.youtube.com/watch?v=zCO6uf6XXRw

                  It is working good so far, only the position is hard-coded maybe i need to use the parentWidget size and figure out the bottom right corner somehow.

                  Current code :

                  @void AchievementWidget::startAnimate() {

                  setVisible(true);
                  
                  /// Todo; put achievement icon here
                  ui->label_icon->setStyleSheet("image: url(:/image/icon/burn)");
                  

                  // qDebug() << "X, y" << this->x() << this->y();
                  // qDebug() << "width, height" << this->width() << this->height();

                  QPropertyAnimation *animation = new QPropertyAnimation(this, "pos");
                  animation->setDuration(1000);
                  animation->setStartValue(QPoint(this->x() + this->width() - 190, this->y() + this->height() - 5) ) ;
                  animation->setEndValue(QPoint(this->x() + this->width() - 190, this->y() + this->height() - 75 ) ) ;
                  animation->start(QAbstractAnimation::DeleteWhenStopped);
                  
                  timerRemoveAnimation->start(2000);
                  

                  }

                  /////////////////////////////////////////////////////////////////////////////////////////////
                  void AchievementWidget::removeFromScreen() {

                  QPropertyAnimation *animation = new QPropertyAnimation(this, "pos");
                  animation->setDuration(1000);
                  animation->setStartValue(QPoint(this->x() + this->width() - 190, this->y() + this->height() - 75 ) ) ;
                  animation->setEndValue(QPoint(this->x() + this->width() - 190, this->y() + this->height() - 5) ) ;
                  animation->start(QAbstractAnimation::DeleteWhenStopped);
                  
                  timerSetNotVisible->start(1000);
                  

                  }

                  /////////////////////////////////////////////////////////////////////////////////////////////
                  void AchievementWidget::setNotVisible() {

                  setVisible(false);
                  

                  }
                  @


                  Free Indoor Cycling Software - https://maximumtrainer.com

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #13

                    You should move the animation in the parent widget. AchievementWidget's task is just to show the achievements. The parent widget is responsible for showing it at the right place. Also moving the animation to the parent widget, you'll have access to the geometry of it and you can setup the animation cleanly.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      maximus
                      wrote on last edited by
                      #14

                      Hey SGaist,
                      I've been trying some idea on this AchievementWidget.

                      Since the position of the Widget is always on the bottom right of the user screen, I coded the geometry directly in the Widget (not the parent). I also made the Widget parentless, so that it can be shown anywhere on the screen.

                      Here is the result:
                      https://www.dropbox.com/s/hvrgtvdx7f1s3pr/AchievementEx1.png

                      As you can see, without a parent, the Widget is shown like a window, a taskbar item is added, as well with close, expand button on the window. and If I had a parent, the widget does not show because the location if outside of the parent widget geometry.

                      I think I could fix it if I just find how to remove the QWidget frame and show it like it is when it has a parent (no frame, no topbar button..)

                      Here is the current code :

                      Instantiation in the parent class, notice no parent is passed here:
                      @ achievementWidget = new AchievementWidget();
                      achievementWidget->setAttribute(Qt::WA_TransparentForMouseEvents,true);
                      achievementWidget->setVisible(false);@

                      What is called when achievement is unlocked:
                      @void AchievementWidget::startAnimate() {

                      setVisible(true);
                      
                      /// Todo; put achievement icon here
                      ui->label_icon->setStyleSheet("image: url(:/image/icon/burn)");
                      
                      
                      /// Get bottom right corner of current screen
                      QRect rectDesktop = QApplication::desktop()->availableGeometry();
                      
                      //    qDebug() << "rectDesktop size is" << rectDesktop;
                      /// Widget Size is fixed to 190x75, bottom right corner
                      QPoint bottonRight(rectDesktop.bottomRight());
                      QPoint bottonRightBeforeAnim = QPoint(bottonRight.x() - 190, bottonRight.y());
                      QPoint bottonRightAfterAnim =  QPoint(bottonRight.x() - 190, bottonRight.y() - 75);
                      
                      qDebug() << "point is" << bottonRightBeforeAnim;
                      qDebug() << "point is" << bottonRightAfterAnim;
                      
                      QPropertyAnimation *animation = new QPropertyAnimation(this, "pos");
                      animation->setDuration(1000);
                      animation->setStartValue(bottonRightBeforeAnim) ;
                      animation->setEndValue(bottonRightAfterAnim) ;
                      animation->start(QAbstractAnimation::DeleteWhenStopped);
                      
                      timerRemoveAnimation->start(4000);
                      

                      }@

                      Thanks!


                      Free Indoor Cycling Software - https://maximumtrainer.com

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        maximus
                        wrote on last edited by
                        #15

                        Woot! fixed with theses flags in my QWidget :
                        @ setAutoFillBackground(true);
                        setAttribute(Qt::WA_NoMousePropagation);
                        setWindowFlags(Qt::WindowStaysOnTopHint);
                        setWindowFlags(Qt::X11BypassWindowManagerHint);
                        setWindowFlags(Qt::FramelessWindowHint );@

                        New result :
                        https://www.dropbox.com/s/ei4w4796azo5boy/achievementV2Working.png


                        Free Indoor Cycling Software - https://maximumtrainer.com

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved