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. QMovie for each button displaying a gif in the json file
Forum Updated to NodeBB v4.3 + New Features

QMovie for each button displaying a gif in the json file

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 255 Views
  • 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.
  • K Offline
    K Offline
    Kris Revi
    wrote on last edited by Kris Revi
    #1

    My function

    void MainWindow::populatePatternList()
    {
        QFile file(filemanager->savePath + filemanager->folderData + filemanager->fileJsonPattern);
        QByteArray jsonArray;
    
        if ( file.open(QIODevice::ReadOnly | QIODevice::Text) )
        {
            jsonArray = file.readAll();
            debugger.LevelSuccess("PATTERNLIST", "OPEN", "File was opened and read", "");
            file.close();
        }
    
        QJsonParseError error;
        QJsonDocument doc = QJsonDocument::fromJson(jsonArray, &error);
    
        if (error.error != QJsonParseError::NoError) {
            qDebug() << "Failed to parse JSON" << error.errorString();
            return;
        }
    
        QJsonObject object = doc.object();
    
        QJsonArray value = object.find("Pattern")->toArray();
    
        QScrollArea *scrollArea = new QScrollArea(ui->framePatternMenuContainer);
        scrollArea->setWidgetResizable(true);
        scrollArea->setStyleSheet("border: none;background:transparent;");
        scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    
        QWidget *widget = new QWidget();
        scrollArea->setWidget(widget);
    
        QVBoxLayout *layout = new QVBoxLayout(widget);
        layout->setContentsMargins(0, 0, 0, 0);
        layout->setSpacing(0);
        layout->setAlignment(Qt::AlignTop);
    
        for (auto v : value)
        {
            auto movie = new QMovie(this);
            movie->setFileName(v.toObject().value("button_image").toString());
            movie->start();
    
            QToolButton *button = new QToolButton();
            button->setText(v.toObject().value("button_text").toString());
            button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
            button->setFixedHeight(55);
            button->setMinimumWidth(262);
            button->setToolTip(v.toObject().value("button_tooltip").toString());
            connect(movie, &QMovie::frameChanged, [=]() { button->setIcon(movie->currentPixmap()); });
            button->setIconSize(QSize(200,32));
            button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
            button->setStyleSheet("QToolButton {"
                                  "font: 25 10pt 'Bahnschrift Light';"
                                  "color:#999e98;"
                                  "text-align:center;"
                                  "background-color: rgb(24, 24, 24);"
                                  "background:none;"
                                  "border-radius: none;"
                                  "}"
                                  "QToolButton:hover {"
                                  "background:#dcdfe3;"
                                  "border-radius: none;"
                                  "}");
            button->setCursor(Qt::PointingHandCursor);
            connect(button, &QToolButton::clicked, [=, button_id = v.toObject().value("button_id").toInt()]() { wled->setSegmentEffect(button_id);});
            layout->addWidget(button);
        }
        QGridLayout *gridLayout = new QGridLayout(ui->framePatternMenuContainer);
        gridLayout->addWidget(scrollArea);
        gridLayout->setContentsMargins(0, 0, 0, 0);
    }
    

    The problem here is that Button 1 does not show its gif at all but Button 2 does what am i doing wrong?

    JonBJ 1 Reply Last reply
    0
    • K Offline
      K Offline
      Kris Revi
      wrote on last edited by
      #4

      i found the "problem"... the first button has a .gif image BUT it is not animated... just named .gif so i figured that is why the QMovie is NOT showing it :)

      1 Reply Last reply
      0
      • K Kris Revi

        My function

        void MainWindow::populatePatternList()
        {
            QFile file(filemanager->savePath + filemanager->folderData + filemanager->fileJsonPattern);
            QByteArray jsonArray;
        
            if ( file.open(QIODevice::ReadOnly | QIODevice::Text) )
            {
                jsonArray = file.readAll();
                debugger.LevelSuccess("PATTERNLIST", "OPEN", "File was opened and read", "");
                file.close();
            }
        
            QJsonParseError error;
            QJsonDocument doc = QJsonDocument::fromJson(jsonArray, &error);
        
            if (error.error != QJsonParseError::NoError) {
                qDebug() << "Failed to parse JSON" << error.errorString();
                return;
            }
        
            QJsonObject object = doc.object();
        
            QJsonArray value = object.find("Pattern")->toArray();
        
            QScrollArea *scrollArea = new QScrollArea(ui->framePatternMenuContainer);
            scrollArea->setWidgetResizable(true);
            scrollArea->setStyleSheet("border: none;background:transparent;");
            scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        
            QWidget *widget = new QWidget();
            scrollArea->setWidget(widget);
        
            QVBoxLayout *layout = new QVBoxLayout(widget);
            layout->setContentsMargins(0, 0, 0, 0);
            layout->setSpacing(0);
            layout->setAlignment(Qt::AlignTop);
        
            for (auto v : value)
            {
                auto movie = new QMovie(this);
                movie->setFileName(v.toObject().value("button_image").toString());
                movie->start();
        
                QToolButton *button = new QToolButton();
                button->setText(v.toObject().value("button_text").toString());
                button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
                button->setFixedHeight(55);
                button->setMinimumWidth(262);
                button->setToolTip(v.toObject().value("button_tooltip").toString());
                connect(movie, &QMovie::frameChanged, [=]() { button->setIcon(movie->currentPixmap()); });
                button->setIconSize(QSize(200,32));
                button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                button->setStyleSheet("QToolButton {"
                                      "font: 25 10pt 'Bahnschrift Light';"
                                      "color:#999e98;"
                                      "text-align:center;"
                                      "background-color: rgb(24, 24, 24);"
                                      "background:none;"
                                      "border-radius: none;"
                                      "}"
                                      "QToolButton:hover {"
                                      "background:#dcdfe3;"
                                      "border-radius: none;"
                                      "}");
                button->setCursor(Qt::PointingHandCursor);
                connect(button, &QToolButton::clicked, [=, button_id = v.toObject().value("button_id").toInt()]() { wled->setSegmentEffect(button_id);});
                layout->addWidget(button);
            }
            QGridLayout *gridLayout = new QGridLayout(ui->framePatternMenuContainer);
            gridLayout->addWidget(scrollArea);
            gridLayout->setContentsMargins(0, 0, 0, 0);
        }
        

        The problem here is that Button 1 does not show its gif at all but Button 2 does what am i doing wrong?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #2

        @Kris-Revi
        What "gif"??

        movie->setFileName(v.toObject().value("button_image").toString());

        What have you done to error check this? How do you or we know what filename/path that resolves to and whether it even exists? If it does not exist for the first but does for the second one button, would that explain the behaviour you see?

        K 1 Reply Last reply
        0
        • JonBJ JonB

          @Kris-Revi
          What "gif"??

          movie->setFileName(v.toObject().value("button_image").toString());

          What have you done to error check this? How do you or we know what filename/path that resolves to and whether it even exists? If it does not exist for the first but does for the second one button, would that explain the behaviour you see?

          K Offline
          K Offline
          Kris Revi
          wrote on last edited by Kris Revi
          #3

          @JonB the json file looks like this

          {
              "Pattern": [
                  {
                      "button_id": "0",
                      "button_text": "Solid",
                      "button_image": ":/image/patterns/FX_SOLID.gif",
                      "button_tooltip": "Solid primary color on all LEDs"
                  },
                  {
                      "button_id": "1",
                      "button_text": "Blink",
                      "button_image": ":/image/patterns/FX_BLINK.gif",
                      "button_tooltip": "Blinks between primary and secondary color"
                  }
              ]
          }
          

          @JonB said in QMovie for each button displaying a gif in the json file:

          What have you done to error check this? How do you or we know what filename/path that resolves to and whether it even exists? If it does not exist for the first but does for the second one button, would that explain the behaviour you see?

          well it is weird that Button 2 (button id 1) has the image shown but button 1 (button id 0) has not
          the image exsist! i have checked and they are in the .qrc file :)

          1 Reply Last reply
          0
          • K Offline
            K Offline
            Kris Revi
            wrote on last edited by
            #4

            i found the "problem"... the first button has a .gif image BUT it is not animated... just named .gif so i figured that is why the QMovie is NOT showing it :)

            1 Reply Last reply
            0
            • K Kris Revi has marked this topic as solved on

            • Login

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