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. get windows preview image for a file
Forum Updated to NodeBB v4.3 + New Features

get windows preview image for a file

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 4 Posters 1.8k 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.
  • ODБOïO Offline
    ODБOïO Offline
    ODБOï
    wrote on last edited by
    #1

    Hello,

    I want to make GCode preview feature in my QtQuick application.

    i installed a softwere called thumbnailcnc, now in my Pc when i go to the folder where my GCode files are stored, i see a preview of files instead of white rectangles (as files are usually represented in windows)

    My question is : Can my qt application get that preview as an image ?

    thank you

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

      Hi
      I have not seen any Qt way, however, you can use native API to do it
      https://code.msdn.microsoft.com/windowsapps/File-thumbnails-sample-17575959
      there is c++ sample.

      update:
      you could also maybe cheat a bit and use
      https://thumbcacheviewer.github.io/
      as it has a cmd line version so maybe you could run
      it on a folder (using QProcess) and export the images to files.
      Not tested if possible. was just a thought.

      ODБOïO 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        I have not seen any Qt way, however, you can use native API to do it
        https://code.msdn.microsoft.com/windowsapps/File-thumbnails-sample-17575959
        there is c++ sample.

        update:
        you could also maybe cheat a bit and use
        https://thumbcacheviewer.github.io/
        as it has a cmd line version so maybe you could run
        it on a folder (using QProcess) and export the images to files.
        Not tested if possible. was just a thought.

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

        @mrjj thank you very much I will dig these 2 potential solutions.

        my final goal is to click on a file and see its preview in my quick app, so more natual solution is to integrate a gcode viewer in my app instead of using the os things but i could not find any gcode parser/viewer that i m able to integrate. do you know one ?

        JonBJ 1 Reply Last reply
        0
        • ODБOïO ODБOï

          @mrjj thank you very much I will dig these 2 potential solutions.

          my final goal is to click on a file and see its preview in my quick app, so more natual solution is to integrate a gcode viewer in my app instead of using the os things but i could not find any gcode parser/viewer that i m able to integrate. do you know one ?

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

          @LeLev
          So for what is available would Googling gcode viewer source code and looking at some of those hopefully give you some C++ source you can use? https://github.com/jtronics/G-Code-jViewer actually says it's QT-based, I'm hoping it's really Qt-based :)

          ODБOïO 2 Replies Last reply
          1
          • JonBJ JonB

            @LeLev
            So for what is available would Googling gcode viewer source code and looking at some of those hopefully give you some C++ source you can use? https://github.com/jtronics/G-Code-jViewer actually says it's QT-based, I'm hoping it's really Qt-based :)

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

            @JonB thank you
            i tryed 4 or 5 things and shamefully failed to integrate with my project as i said... I heve one Gcode to segment js library and im planning to use it with qml canvas 2d to draw the path.

            I just wanted to see if someone knows a ready to use solution, who knows with Qt..! i already had nice surprises with @SGaist suggesting qvncclient or the arrival of qtopcua..

            1 Reply Last reply
            1
            • JonBJ JonB

              @LeLev
              So for what is available would Googling gcode viewer source code and looking at some of those hopefully give you some C++ source you can use? https://github.com/jtronics/G-Code-jViewer actually says it's QT-based, I'm hoping it's really Qt-based :)

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

              @JonB said in get windows preview image for a file:

              some C++ source

              it is a standalone software, no sources unfortunately

              1 Reply Last reply
              0
              • ODБOïO Offline
                ODБOïO Offline
                ODБOï
                wrote on last edited by
                #7

                hi,i found this project. It works wery well. The only problem is i cant figure out how to use just a little part of it (open file and generate a preview) in my app,

                Could you please give a hint on how to integrate it with my qt quick project ?

                https://github.com/zapmaker/GrblHoming.git

                i would like to create mu QQuickPaintedItem that shows the preview
                thank you

                1 Reply Last reply
                0
                • ODБOïO Offline
                  ODБOïO Offline
                  ODБOï
                  wrote on last edited by
                  #8

                  i try to link the GrblHoming project to mine, only by

                  INCLUDEPATH += c:/users/lev/documents/dev/GrblHoming

                  there is a RenderArea class in GrblHoming project, im trying to create my own render area with QQuickPaintedItem base class

                  #ifndef GCODEVIEW_H
                  #define GCODEVIEW_H
                  #include <QtQuick/QQuickPaintedItem>
                  #include "renderarea.h"
                  #include "positem.h"
                  #include "renderitemlist.h"
                  
                  class GCodeView : public QQuickPaintedItem
                  {
                  public:
                      GCodeView(QQuickItem *parent = 0);
                  
                  public slots:
                      void setItems(QList<PosItem>);
                      void setLivePoint(double x, double y, bool isMM, bool isLiveCP);
                      void setVisualLivenessCurrPos(bool isLiveCP);
                      void setVisCurrLine(int currLine);
                  
                  protected:
                      void paintEvent(QPaintEvent *event);
                  
                  private:
                      QList<PosItem> items;
                      RenderItemList listToRender;
                      QPen penProposedPath, penAxes, penCoveredPath, penCurrPosActive, penCurrPosInactive, penMeasure;
                      PosItem livePoint;
                      bool isLiveCurrPos;
                  };
                  
                  #endif // GCODEVIEW_H
                  
                  //.cpp
                  
                  #include "gcodeview.h"
                  #include <QPainter>
                  GCodeView::GCodeView(QQuickItem *parent): QQuickPaintedItem(parent)
                  {}
                  
                  void GCodeView::setItems(QList<PosItem> itemsRcvd)
                  {
                      items = itemsRcvd;
                  
                      listToRender.setCurrFileLine(0);
                      listToRender.convertList(items);
                      listToRender.updateLivePoint();
                      update();
                  }
                  
                  void GCodeView::setLivePoint(double x, double y, bool mm, bool isLiveCP)
                  {
                      isLiveCurrPos = isLiveCP;
                      livePoint.setCoords(x, y, mm);
                      listToRender.setLivePoint(livePoint);
                      update();
                  
                  }
                  
                  void GCodeView::setVisualLivenessCurrPos(bool isLiveCP)
                  {
                      isLiveCurrPos = isLiveCP;
                  }
                  
                  void GCodeView::setVisCurrLine(int currLine)
                  {
                      if (listToRender.setCurrFileLine(currLine))
                          update();
                  }
                  
                  void GCodeView::paintEvent(QPaintEvent * /* event */)
                  {
                      if (!items.size())
                          return;
                  
                      QSize size(this->size().height(),this->size().width());
                  
                      listToRender.rescale(size);
                  
                      QPainter painter;
                  
                      painter.setPen(penProposedPath);
                      listToRender.writePath(painter, false);
                  
                      painter.setPen(penAxes);
                      listToRender.drawAxes(painter);
                  
                      painter.setPen(penMeasure);
                      listToRender.drawMeasurements(painter);
                  
                      painter.setPen(penCoveredPath);
                      listToRender.writePath(painter, true);
                  
                      //if (!livePoint.isNull()) FIX isNull
                      {
                          if (isLiveCurrPos)
                              painter.setPen(penCurrPosActive);
                          else
                              painter.setPen(penCurrPosInactive);
                          listToRender.drawPoint(painter, livePoint);
                      }
                  }
                  
                  

                  but this causes compil errors even if i don't use this class yet

                  gcodeview.obj:-1: erreur : LNK2019: symbole unresolved  "public: __cdecl RenderItemList::RenderItemList(void)" (??0RenderItemList@@QEAA@XZ) référencé dans la fonction "public: __cdecl GCodeView::GCodeView(class QQuickItem *)" (??0GCodeView@@QEAA@PEAVQQuickItem@@@Z)
                  
                  gcodeview.obj:-1: erreur : LNK2019: symbole externe non résolu "public: virtual __cdecl RenderItemList::~RenderItemList(void)" (??1RenderItemList@@UEAA@XZ) référencé dans la fonction "int `public: __cdecl GCodeView::GCodeView(class QQuickItem *)'::`1'::dtor$2" (?dtor$2@?0???0GCodeView@@QEAA@PEAVQQuickItem@@@Z@4HA)
                  
                  gcodeview.obj:-1: erreur : LNK2019: symbole externe non résolu "public: void __cdecl RenderItemList::convertList(class QList<class PosItem> const &)" (?convertList@RenderItemList@@QEAAXAEBV?$QList@VPosItem@@@@@Z) référencé dans la fonction "public: void __cdecl GCodeView::setItems(class QList<class PosItem>)" (?setItems@GCodeView@@QEAAXV?$QList@VPosItem@@@@@Z)
                  
                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Hi
                    Did you also take renderitemlist.cpp and added to your project ?
                    Just seems like normal linker errors as it sees the stuff in .h but finds no
                    body/implementation fo rit.

                    ODБOïO 2 Replies Last reply
                    1
                    • mrjjM mrjj

                      Hi
                      Did you also take renderitemlist.cpp and added to your project ?
                      Just seems like normal linker errors as it sees the stuff in .h but finds no
                      body/implementation fo rit.

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

                      @mrjj no my bad

                      1 Reply Last reply
                      0
                      • mrjjM mrjj

                        Hi
                        Did you also take renderitemlist.cpp and added to your project ?
                        Just seems like normal linker errors as it sees the stuff in .h but finds no
                        body/implementation fo rit.

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

                        @mrjj i have no more linkage errors, but i cant use qmlRegisterType() to expose my class to qml

                        qmlRegisterType<GCodeView>("GC", 1 ,0 , "gcode");

                        i have erros saying C:\Qt\5.13.0\msvc2017_64\include\QtQml\qqmlprivate.h:124: error: C2259: 'QQmlPrivate::QQmlElement<T>'ÿ: impossible to create an object from abstract class
                        with
                        [
                        T=GCodeView
                        ]

                        this i smy class

                        #ifndef GCODEVIEW_H
                        #define GCODEVIEW_H
                        #include <QtQuick/QQuickPaintedItem>
                        //#include "renderarea.h"
                        #include "positem.h"
                        #include "renderitemlist.h"
                        
                        
                        
                        
                        
                        class GCodeView : public QQuickPaintedItem
                        {
                        public:
                            GCodeView(QQuickItem *parent = 0);
                        
                        public slots:
                            void setItems(QList<PosItem>);
                            void setLivePoint(double x, double y, bool isMM, bool isLiveCP);
                            void setVisualLivenessCurrPos(bool isLiveCP);
                            void setVisCurrLine(int currLine);
                        
                        
                        protected:
                            void paint();
                        
                        private:
                            QList<PosItem> items;
                            RenderItemList listToRender;
                            QPen penProposedPath, penAxes, penCoveredPath, penCurrPosActive, penCurrPosInactive, penMeasure;
                            PosItem livePoint;
                            bool isLiveCurrPos;
                        };
                        
                        #endif // GCODEVIEW_H
                        //-------------------------------------------------CPP----------------------------------------
                        #include "gcodeview.h"
                        #include <QPainter>
                        GCodeView::GCodeView(QQuickItem *parent): QQuickPaintedItem(parent)
                        {
                        
                        }
                        
                        
                        void GCodeView::setItems(QList<PosItem> itemsRcvd)
                        {
                            items = itemsRcvd;
                        
                            listToRender.setCurrFileLine(0);
                            listToRender.convertList(items);
                            listToRender.updateLivePoint();
                            update();
                        }
                        
                        
                        void GCodeView::setLivePoint(double x, double y, bool mm, bool isLiveCP)
                        {
                            isLiveCurrPos = isLiveCP;
                            livePoint.setCoords(x, y, mm);
                            listToRender.setLivePoint(livePoint);
                            update();
                        
                        }
                        
                        void GCodeView::setVisualLivenessCurrPos(bool isLiveCP)
                        {
                            isLiveCurrPos = isLiveCP;
                        }
                        
                        void GCodeView::setVisCurrLine(int currLine)
                        {
                            if (listToRender.setCurrFileLine(currLine))
                                update();
                        }
                        
                        void GCodeView::paint(/*QPaintEvent */ /* event */)
                        {
                            if (!items.size())
                                return;
                        
                            QSize size(this->size().height(),this->size().width());
                        
                            listToRender.rescale(size);
                        
                            QPainter painter;
                        
                            painter.setPen(penProposedPath);
                            listToRender.writePath(painter, false);
                        
                            painter.setPen(penAxes);
                            listToRender.drawAxes(painter);
                        
                            painter.setPen(penMeasure);
                            listToRender.drawMeasurements(painter);
                        
                            painter.setPen(penCoveredPath);
                            listToRender.writePath(painter, true);
                        
                            //if (!livePoint.isNull()) FIX isNull
                            {
                                if (isLiveCurrPos)
                                    painter.setPen(penCurrPosActive);
                                else
                                    painter.setPen(penCurrPosInactive);
                                listToRender.drawPoint(painter, livePoint);
                            }
                        }
                        
                        
                        jsulmJ 1 Reply Last reply
                        0
                        • ODБOïO ODБOï

                          @mrjj i have no more linkage errors, but i cant use qmlRegisterType() to expose my class to qml

                          qmlRegisterType<GCodeView>("GC", 1 ,0 , "gcode");

                          i have erros saying C:\Qt\5.13.0\msvc2017_64\include\QtQml\qqmlprivate.h:124: error: C2259: 'QQmlPrivate::QQmlElement<T>'ÿ: impossible to create an object from abstract class
                          with
                          [
                          T=GCodeView
                          ]

                          this i smy class

                          #ifndef GCODEVIEW_H
                          #define GCODEVIEW_H
                          #include <QtQuick/QQuickPaintedItem>
                          //#include "renderarea.h"
                          #include "positem.h"
                          #include "renderitemlist.h"
                          
                          
                          
                          
                          
                          class GCodeView : public QQuickPaintedItem
                          {
                          public:
                              GCodeView(QQuickItem *parent = 0);
                          
                          public slots:
                              void setItems(QList<PosItem>);
                              void setLivePoint(double x, double y, bool isMM, bool isLiveCP);
                              void setVisualLivenessCurrPos(bool isLiveCP);
                              void setVisCurrLine(int currLine);
                          
                          
                          protected:
                              void paint();
                          
                          private:
                              QList<PosItem> items;
                              RenderItemList listToRender;
                              QPen penProposedPath, penAxes, penCoveredPath, penCurrPosActive, penCurrPosInactive, penMeasure;
                              PosItem livePoint;
                              bool isLiveCurrPos;
                          };
                          
                          #endif // GCODEVIEW_H
                          //-------------------------------------------------CPP----------------------------------------
                          #include "gcodeview.h"
                          #include <QPainter>
                          GCodeView::GCodeView(QQuickItem *parent): QQuickPaintedItem(parent)
                          {
                          
                          }
                          
                          
                          void GCodeView::setItems(QList<PosItem> itemsRcvd)
                          {
                              items = itemsRcvd;
                          
                              listToRender.setCurrFileLine(0);
                              listToRender.convertList(items);
                              listToRender.updateLivePoint();
                              update();
                          }
                          
                          
                          void GCodeView::setLivePoint(double x, double y, bool mm, bool isLiveCP)
                          {
                              isLiveCurrPos = isLiveCP;
                              livePoint.setCoords(x, y, mm);
                              listToRender.setLivePoint(livePoint);
                              update();
                          
                          }
                          
                          void GCodeView::setVisualLivenessCurrPos(bool isLiveCP)
                          {
                              isLiveCurrPos = isLiveCP;
                          }
                          
                          void GCodeView::setVisCurrLine(int currLine)
                          {
                              if (listToRender.setCurrFileLine(currLine))
                                  update();
                          }
                          
                          void GCodeView::paint(/*QPaintEvent */ /* event */)
                          {
                              if (!items.size())
                                  return;
                          
                              QSize size(this->size().height(),this->size().width());
                          
                              listToRender.rescale(size);
                          
                              QPainter painter;
                          
                              painter.setPen(penProposedPath);
                              listToRender.writePath(painter, false);
                          
                              painter.setPen(penAxes);
                              listToRender.drawAxes(painter);
                          
                              painter.setPen(penMeasure);
                              listToRender.drawMeasurements(painter);
                          
                              painter.setPen(penCoveredPath);
                              listToRender.writePath(painter, true);
                          
                              //if (!livePoint.isNull()) FIX isNull
                              {
                                  if (isLiveCurrPos)
                                      painter.setPen(penCurrPosActive);
                                  else
                                      painter.setPen(penCurrPosInactive);
                                  listToRender.drawPoint(painter, livePoint);
                              }
                          }
                          
                          
                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @LeLev said in get windows preview image for a file:

                          QQuickPaintedItem

                          Override paint() method correctly. It is pure virtual in QQuickPaintedItem and you overloaded it instead of overriding it (it has aparameter: https://doc.qt.io/qt-5/qquickpainteditem.html#paint).

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          ODБOïO 1 Reply Last reply
                          2
                          • jsulmJ jsulm

                            @LeLev said in get windows preview image for a file:

                            QQuickPaintedItem

                            Override paint() method correctly. It is pure virtual in QQuickPaintedItem and you overloaded it instead of overriding it (it has aparameter: https://doc.qt.io/qt-5/qquickpainteditem.html#paint).

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

                            nice! now my class works nicely ! thank you @mrjj @JonB @jsulm !

                            edit : im able to display my GCodeView in qml with some test data like :

                                 list.append(PosItem(1,5,4,5));
                                list.append(PosItem(2,8,1,2));
                                list.append(PosItem(4,10,1,0));
                                list.append(PosItem(22,11,5,1));
                            

                            Now i need to parse a file instead of this test data. sadly i have to make a new post for this because i have an issue in my parse method

                            #ifndef GCODEVIEW_H
                            #define GCODEVIEW_H
                            #include <QtQuick/QQuickPaintedItem>
                            //#include "renderarea.h"
                            #include "positem.h"
                            #include "renderitemlist.h"
                            
                            class GCodeView : public QQuickPaintedItem
                            {
                            public:
                                GCodeView(QQuickItem *parent = 0);
                            
                            public slots:
                                void setItems(QList<PosItem>);
                                void setLivePoint(double x, double y, bool isMM, bool isLiveCP);
                                void setVisualLivenessCurrPos(bool isLiveCP);
                                void setVisCurrLine(int currLine);
                            
                            
                            protected:
                                void paint( QPainter *painterp);
                            
                            private:
                                QList<PosItem> items;
                                RenderItemList listToRender;
                                QPen penProposedPath, penAxes, penCoveredPath, penCurrPosActive, penCurrPosInactive, penMeasure;
                                PosItem livePoint;
                                bool isLiveCurrPos;
                            };
                            
                            #endif // GCODEVIEW_H
                            //-----------------------------------------------CPP---------------------------------------------
                            #include "gcodeview.h"
                            #include <QPainter>
                            GCodeView::GCodeView(QQuickItem *parent): QQuickPaintedItem(parent)
                            {
                                QList<PosItem> list;
                            
                               // some simulation data
                                list.append(PosItem(1,5,4,5));
                                list.append(PosItem(2,8,1,2));
                                list.append(PosItem(4,10,1,0));
                                list.append(PosItem(22,11,5,1));
                                list.append(PosItem(1,5,4,5));
                                list.append(PosItem(2,8,1,2));
                                list.append(PosItem(4,10,1,0));
                                list.append(PosItem(22,11,5,1));
                                list.append(PosItem(1,5,4,5));
                                list.append(PosItem(2,8,1,2));
                                list.append(PosItem(4,10,1,0));
                                list.append(PosItem(22,11,5,1));
                            
                                 setItems(list);
                            }
                            
                            
                            void GCodeView::setItems(QList<PosItem> itemsRcvd)
                            {
                                items = itemsRcvd;
                            
                                listToRender.setCurrFileLine(0);
                                listToRender.convertList(items);
                                listToRender.updateLivePoint();
                                update();
                            }
                            
                            
                            void GCodeView::setLivePoint(double x, double y, bool mm, bool isLiveCP)
                            {
                                isLiveCurrPos = isLiveCP;
                                livePoint.setCoords(x, y, mm);
                                listToRender.setLivePoint(livePoint);
                                update();
                            }
                            
                            void GCodeView::setVisualLivenessCurrPos(bool isLiveCP)
                            {
                                isLiveCurrPos = isLiveCP;
                            }
                            
                            void GCodeView::setVisCurrLine(int currLine)
                            {
                                if (listToRender.setCurrFileLine(currLine))
                                    update();
                            }
                            
                            void GCodeView::paint(QPainter *painter)
                            {
                                if (!items.size())
                                    return;
                            
                                QSize size(this->size().height(),this->size().width());
                            
                                listToRender.rescale(size);
                            
                                //QPainter painter;
                            
                                painter->setPen(penProposedPath);
                                listToRender.writePath(*painter, false);
                            
                                painter->setPen(penAxes);
                                listToRender.drawAxes(*painter);
                            
                                painter->setPen(penMeasure);
                                listToRender.drawMeasurements(*painter);
                            
                                painter->setPen(penCoveredPath);
                                listToRender.writePath(*painter, true);
                            
                                //if (!livePoint.isNull()) FIX isNull
                                {
                                    if (isLiveCurrPos)
                                        painter->setPen(penCurrPosActive);
                                    else
                                        painter->setPen(penCurrPosInactive);
                                    listToRender.drawPoint(*painter, livePoint);
                                }
                            }
                            //-----------------------------------------------------------------------------------
                             qmlRegisterType<GCodeView>("GCodeView", 1 ,0 , "Gcode");
                            //---------------------------------------QML-----------------------------------------
                            import GCodeView 1.0
                            import "."
                            
                            
                            
                            ApplicationWindow {
                                id: rootmain
                                visible: true
                            
                                Gcode{
                                    anchors.centerIn: parent
                                    height: 150
                                    width: 150
                                }
                            }
                             
                            
                            
                            1 Reply Last reply
                            2

                            • Login

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