Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Create slideshow in qt creator
Forum Update on Monday, May 27th 2025

Create slideshow in qt creator

Scheduled Pinned Locked Moved Solved Mobile and Embedded
qtcreator 5.11qlist
20 Posts 4 Posters 4.1k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi and welcome to devnet,

    What technology are you using ? Widgets or QtQuick ?

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

    R 1 Reply Last reply
    2
    • SGaistS SGaist

      Hi and welcome to devnet,

      What technology are you using ? Widgets or QtQuick ?

      R Offline
      R Offline
      RAJ Dalsaniya
      wrote on last edited by
      #3

      @SGaist i use qt quick with raspberry pi

      ODБOïO 1 Reply Last reply
      0
      • R RAJ Dalsaniya

        @SGaist i use qt quick with raspberry pi

        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #4

        @RAJ-Dalsaniya hi see qml Keys type https://doc.qt.io/qt-5/qml-qtquick-keys.html

        R 1 Reply Last reply
        2
        • ODБOïO ODБOï

          @RAJ-Dalsaniya hi see qml Keys type https://doc.qt.io/qt-5/qml-qtquick-keys.html

          R Offline
          R Offline
          RAJ Dalsaniya
          wrote on last edited by
          #5

          @LeLev how can I implement using c++ only

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

            You wrote that you are using QtQuick but now you want to use C++.

            Did you change technology ?

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

            R 1 Reply Last reply
            1
            • SGaistS SGaist

              You wrote that you are using QtQuick but now you want to use C++.

              Did you change technology ?

              R Offline
              R Offline
              RAJ Dalsaniya
              wrote on last edited by RAJ Dalsaniya
              #7

              @SGaist Yes I try same using widget but problem is when i press key my application crashed. it will give sigabrt signal .. I implement keyevent using keypressevent

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

                If it crashed then there's likely an error in your code. Did you try to debug it ?

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

                R 1 Reply Last reply
                1
                • SGaistS SGaist

                  If it crashed then there's likely an error in your code. Did you try to debug it ?

                  R Offline
                  R Offline
                  RAJ Dalsaniya
                  wrote on last edited by
                  #9

                  @SGaist Yes ...I think way I am access my list of link...it creates trouble..

                  mrjjM 1 Reply Last reply
                  0
                  • R RAJ Dalsaniya

                    @SGaist Yes ...I think way I am access my list of link...it creates trouble..

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @RAJ-Dalsaniya
                    Hi
                    please show the c++ code then. :)

                    1 Reply Last reply
                    1
                    • R Offline
                      R Offline
                      RAJ Dalsaniya
                      wrote on last edited by
                      #11

                      f1_image.cpp

                      #include "f1_image.h"
                      #include "ui_f1_image.h"
                      
                      #include<QGraphicsView>
                      #include<QStringList>
                      #include<QList>
                      #include<QDir>
                      #include<iostream>
                      #include<QWidget>
                      #include <QKeyEvent>
                      #include <QStringList>
                      
                      
                      class f1_image_private
                      {
                      public:
                          f1_image_private();
                      
                          int CurrentSlide;
                      
                      };
                      
                      F1_Image::F1_Image(QDialog *parent) :
                          QDialog(parent),
                          ui(new Ui::F1_Image)
                      {
                          ui->setupUi(this);
                          filenames.append(":/f1/F1_IMG/city.jpg");
                          filenames.append(":/f1/F1_IMG/cycle.jpg");
                          filenames.append(":/f1/F1_IMG/design.jpg");
                          filenames.append(":/f1/F1_IMG/nature.jpg");
                          filenames.append(":/f1/F1_IMG/tree.jpg");
                      
                      }
                      
                      F1_Image::~F1_Image()
                      {
                          delete ui;
                      }
                      
                      void F1_Image::paintEvent(QPaintEvent *event)
                      {
                          QPainter painter(this);
                          painter.setRenderHint(QPainter::Antialiasing, false);
                          if (filenames.size() > 0)
                          {
                              ui->image->setPixmap(filenames.at(i));
                          }
                      }
                      
                      void F1_Image::keyPressEvent(QKeyEvent* event)
                      {
                          if(event->key()==Qt::Key_Left)
                          {
                              i++ ;
                          }
                          else if(event->key()==Qt::Key_Right)
                          {
                              i--;
                          }
                      
                      }
                      

                      f1_image.h

                      #ifndef F1_IMAGE_H
                      #define F1_IMAGE_H
                      
                      #include <QDialog>
                      #include <QStringList>
                      #include <QGraphicsScene>
                      
                      namespace Ui {
                      class F1_Image;
                      }
                      
                      class F1_image_private;
                      
                      class F1_Image : public QDialog
                      {
                          Q_OBJECT
                      
                      public:
                          explicit F1_Image(QDialog *parent = nullptr);
                          ~F1_Image();
                          void addImage(QStringList filenames);
                      
                          QStringList filenames;
                          int i=0;
                      
                      private:
                          Ui::F1_Image *ui;
                          Ui::F1_Image *d;
                          QPixmap image;
                          QImage *imageObject;
                          QGraphicsScene *scene;
                      
                      signals:
                          void inputReceived();
                      
                      protected:
                           void keyPressEvent(QKeyEvent *event);
                           void paintEvent(QPaintEvent *event);
                          // void showEvent(QShowEvent *event );
                      };
                      
                      

                      @SGaist @mrjj this is my code. i am not sure where excatly i am doing wrong. can you please help me??

                      1 Reply Last reply
                      0
                      • mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by mrjj
                        #12

                        Hi
                        It does not look very wrong.
                        At least not something app should crash from.
                        (not unless you press right from start and i becomes -1)

                        You don't need the
                        void F1_Image::paintEvent(QPaintEvent *event)
                        as the QLabel can paint itself and since you are
                        not painting anything else it seems wasted.
                        However, in sample, i used to print i on same form.

                        You can call setPixmap in keypressEvent

                        void F1_Image::keyPressEvent(QKeyEvent* event)
                        {
                            if(event->key()==Qt::Key_Left)
                            {
                                i++ ;
                            }
                            else if(event->key()==Qt::Key_Right)
                            {
                                i--;
                            }
                        
                         
                            int maxSize = filenames.size() - 1;
                            // checks to make it round trip / avoid crashing
                            if (i > maxSize) { i = 0; }
                            if (i < 0 ) { i = maxSize; }
                        
                            if (i <= maxSize && i >= 0) {
                                ui->label->setPixmap(filenames.at(i));
                            }
                        
                        }
                        

                        also in .h
                        Ui::F1_Image *d;
                        That looks a little odd but just a pointer so should not do anything.

                        Make sure that you check i against being negative also.
                        If user press right as first key, the i will be -1 and also crash the list.

                        here is a working sample based on your code.
                        https://www.dropbox.com/s/ykfm3hqr1x3clby/slideshow_test.zip?dl=0

                        R 1 Reply Last reply
                        2
                        • mrjjM mrjj

                          Hi
                          It does not look very wrong.
                          At least not something app should crash from.
                          (not unless you press right from start and i becomes -1)

                          You don't need the
                          void F1_Image::paintEvent(QPaintEvent *event)
                          as the QLabel can paint itself and since you are
                          not painting anything else it seems wasted.
                          However, in sample, i used to print i on same form.

                          You can call setPixmap in keypressEvent

                          void F1_Image::keyPressEvent(QKeyEvent* event)
                          {
                              if(event->key()==Qt::Key_Left)
                              {
                                  i++ ;
                              }
                              else if(event->key()==Qt::Key_Right)
                              {
                                  i--;
                              }
                          
                           
                              int maxSize = filenames.size() - 1;
                              // checks to make it round trip / avoid crashing
                              if (i > maxSize) { i = 0; }
                              if (i < 0 ) { i = maxSize; }
                          
                              if (i <= maxSize && i >= 0) {
                                  ui->label->setPixmap(filenames.at(i));
                              }
                          
                          }
                          

                          also in .h
                          Ui::F1_Image *d;
                          That looks a little odd but just a pointer so should not do anything.

                          Make sure that you check i against being negative also.
                          If user press right as first key, the i will be -1 and also crash the list.

                          here is a working sample based on your code.
                          https://www.dropbox.com/s/ykfm3hqr1x3clby/slideshow_test.zip?dl=0

                          R Offline
                          R Offline
                          RAJ Dalsaniya
                          wrote on last edited by
                          #13

                          @mrjj now my application don't crashing but it doesn't show images.

                          mrjjM 1 Reply Last reply
                          0
                          • R RAJ Dalsaniya

                            @mrjj now my application don't crashing but it doesn't show images.

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #14

                            @RAJ-Dalsaniya

                            Well your code works fine in the sample
                            so i cannot guess why it does not for you.

                            Use the debugger and check what happens when you press a key
                            and check the the value of i.

                            Also , set an image to the QLabel in CTOR so it has something to show from start.

                            Make sure you check that i is valid.

                            The sample does the above if you have doubts.

                            R 1 Reply Last reply
                            0
                            • mrjjM mrjj

                              @RAJ-Dalsaniya

                              Well your code works fine in the sample
                              so i cannot guess why it does not for you.

                              Use the debugger and check what happens when you press a key
                              and check the the value of i.

                              Also , set an image to the QLabel in CTOR so it has something to show from start.

                              Make sure you check that i is valid.

                              The sample does the above if you have doubts.

                              R Offline
                              R Offline
                              RAJ Dalsaniya
                              wrote on last edited by
                              #15

                              @mrjj I set one other label to check I value and it changed according to keypress but label where I show picture it has some issue..

                              mrjjM 1 Reply Last reply
                              0
                              • R RAJ Dalsaniya

                                @mrjj I set one other label to check I value and it changed according to keypress but label where I show picture it has some issue..

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by mrjj
                                #16

                                @RAJ-Dalsaniya

                                What types of issues ?
                                It is extremely hard to help when you do not describe
                                what happens,
                                what is wrong,
                                What do you see on screen after key pressed.

                                make sure you have valid index (i)

                                 int maxSize = filenames.size() - 1;
                                    // checks to make it round trip / avoid crashing
                                    if (i > maxSize) { i = 0; }
                                    if (i < 0 ) { i = maxSize; }
                                
                                    if (i <= maxSize && i >= 0) {
                                        ui->label->setPixmap(filenames.at(i));
                                    }
                                
                                
                                R 1 Reply Last reply
                                0
                                • mrjjM mrjj

                                  @RAJ-Dalsaniya

                                  What types of issues ?
                                  It is extremely hard to help when you do not describe
                                  what happens,
                                  what is wrong,
                                  What do you see on screen after key pressed.

                                  make sure you have valid index (i)

                                   int maxSize = filenames.size() - 1;
                                      // checks to make it round trip / avoid crashing
                                      if (i > maxSize) { i = 0; }
                                      if (i < 0 ) { i = maxSize; }
                                  
                                      if (i <= maxSize && i >= 0) {
                                          ui->label->setPixmap(filenames.at(i));
                                      }
                                  
                                  
                                  R Offline
                                  R Offline
                                  RAJ Dalsaniya
                                  wrote on last edited by RAJ Dalsaniya
                                  #17

                                  @mrjj When I press key it change I value but it doesn't show picture that available in resource file. Problem is lable don't show picture from list. Can you just check what I write to add all links in filenames is right or not?

                                  mrjjM 1 Reply Last reply
                                  0
                                  • R RAJ Dalsaniya

                                    @mrjj When I press key it change I value but it doesn't show picture that available in resource file. Problem is lable don't show picture from list. Can you just check what I write to add all links in filenames is right or not?

                                    mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #18

                                    @RAJ-Dalsaniya

                                    Hi, find the image file in the project tree to the left side
                                    then right-click it and see the correct path there. then check
                                    what you add to list.

                                    alt text

                                    R 1 Reply Last reply
                                    2
                                    • mrjjM mrjj

                                      @RAJ-Dalsaniya

                                      Hi, find the image file in the project tree to the left side
                                      then right-click it and see the correct path there. then check
                                      what you add to list.

                                      alt text

                                      R Offline
                                      R Offline
                                      RAJ Dalsaniya
                                      wrote on last edited by
                                      #19

                                      @mrjj Thank you so much now it works totally fine .Thank you for your help

                                      mrjjM 1 Reply Last reply
                                      1
                                      • R RAJ Dalsaniya

                                        @mrjj Thank you so much now it works totally fine .Thank you for your help

                                        mrjjM Offline
                                        mrjjM Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #20

                                        @RAJ-Dalsaniya
                                        Super to hear \o/
                                        Please mark as solved using the Topic Tool button at first post :)

                                        1 Reply Last reply
                                        1

                                        • Login

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