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. Showing temperature in a graph.

Showing temperature in a graph.

Scheduled Pinned Locked Moved General and Desktop
13 Posts 4 Posters 5.1k Views 2 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.
  • K Offline
    K Offline
    kamhagh
    wrote on last edited by kamhagh
    #1

    Im making a GPU Temp app for linux And I would like too add a graph. I think Qt has no widget for showing graph so I should make a widget myself.

    I already tried making cosine graph(just for testing) and i couldn't get good results (like the system monitor on linux)
    I first tried calculating Y for each x and keeping the old Y so i can draw a line from the oldY to newY while it worked, it wasn't good looking.

    How can I make a good looking graph widget?

    1 Reply Last reply
    0
    • mrdebugM Offline
      mrdebugM Offline
      mrdebug
      wrote on last edited by
      #2

      Have you tried qwt?

      Need programmers to hire?
      www.labcsp.com
      www.denisgottardello.it
      GMT+1
      Skype: mrdebug

      K 1 Reply Last reply
      0
      • mrdebugM mrdebug

        Have you tried qwt?

        K Offline
        K Offline
        kamhagh
        wrote on last edited by kamhagh
        #3

        @mrdebug No! i will give it a try, but just wondering, what should i do if i wanted to make a graph widget myself?

        edit:
        i get this when trying to install qwt on ubuntu 14.04 lts!

        cd src/ && make -f Makefile
        make[1]: Entering directory /home/k/Documents/qwt-6.1.2/src' compiling qwt_abstract_scale_draw.cpp In file included from qwt_abstract_scale_draw.h:13:0, from qwt_abstract_scale_draw.cpp:10: qwt_global.h:13:21: fatal error: qglobal.h: No such file or directory #include <qglobal.h> ^ compilation terminated. make[1]: *** [obj/qwt_abstract_scale_draw.o] Error 1 make[1]: Leaving directory /home/k/Documents/qwt-6.1.2/src'
        make: *** [sub-src-make_default-ordered] Error 2

        JKSHJ 1 Reply Last reply
        0
        • K kamhagh

          @mrdebug No! i will give it a try, but just wondering, what should i do if i wanted to make a graph widget myself?

          edit:
          i get this when trying to install qwt on ubuntu 14.04 lts!

          cd src/ && make -f Makefile
          make[1]: Entering directory /home/k/Documents/qwt-6.1.2/src' compiling qwt_abstract_scale_draw.cpp In file included from qwt_abstract_scale_draw.h:13:0, from qwt_abstract_scale_draw.cpp:10: qwt_global.h:13:21: fatal error: qglobal.h: No such file or directory #include <qglobal.h> ^ compilation terminated. make[1]: *** [obj/qwt_abstract_scale_draw.o] Error 1 make[1]: Leaving directory /home/k/Documents/qwt-6.1.2/src'
          make: *** [sub-src-make_default-ordered] Error 2

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @kamhagh said:

          **cd src/ && make -f Makefile

          How did you generate that Makefile?

          Open qwt.pro in Qt Creator and build there.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          K 1 Reply Last reply
          0
          • R Offline
            R Offline
            Rondog
            wrote on last edited by Rondog
            #5

            You can make one yourself. You need to get the math right or it will be a mess. This is the important parts for how I did mine:

            // this is the TViewportMat that is used
            
            struct TViewportMat
            {
            	double								tx[2];
            	double								ty[2];
            	double								to[2];
            
            	TViewportMat& operator*=(const TViewportMat &rhs)
            	{
            		double							x,y,o[2];
            
            		x = tx[0] * rhs.tx[0];
            		y = ty[1] * rhs.ty[1];
            		o[0] = to[0] * rhs.tx[0] + rhs.to[0];
            		o[1] = to[1] * rhs.ty[1] + rhs.to[1];
            
            		tx[0] = x;
            		ty[1] = y;
            		to[0] = o[0];
            		to[1] = o[1];
            
            		return *this;
            	}
            
            	void TranslateToWin(const double Xd, const double Yd, int *X, int *Y) const
            	{
            		*X = static_cast<int>(Xd * tx[0] + to[0]);
            		*Y = static_cast<int>(Yd * ty[1] + to[1]);
            	}
            
            	void TranslateFromWin(const int X,const int Y,double *Xd,double *Yd) const
            	{
            		*Xd = (static_cast<double>(X) - to[0]) / tx[0];
            		*Yd = (static_cast<double>(Y) - to[1]) / ty[1];
            	}
            };
            
            
            // This updates an instance of 'TViewportMat' based on a combination of your data (the X and Y range) and the size of the widget area you plan to draw on.
            
            void TGraphWidget::CalculateViewport(void)
            {
                double                              MinX,MaxX,MinY,MaxY,RangeX,RangeY
                TViewportMat                        W,S,V;
             
            // find values for MinX, MaxX, MinY, MaxY from your data
            // make sure difference between Min and Max limits has a minimum value.  I use 0.00005.
            // add a margin by increasing the Min and Max limits slightly
            	
                W.tx[0] = 1;
                W.tx[1] = 0;
                W.ty[0] = 0;
                W.ty[1] = 1;
                W.to[0] = -MinX;
                W.to[1] = -MinY;
            
            // d_GraphRect is the rect for the area the graph occupies.
            // should be the area of the widget or at least the part the graph will occupy
            
                S.tx[0] = (d_GraphRect.right() - d_GraphRect.left()) / (MaxX - MinX);
                S.tx[1] = 0;
                S.ty[0] = 0;
                S.ty[1] = (d_GraphRect.top() - d_GraphRect.bottom()) / (MaxY - MinY);
                S.to[0] = 0;
                S.to[1] = 0;
            
                V.tx[0] = 1;
                V.tx[1] = 0;
                V.ty[0] = 0;
                V.ty[1] = 1;
                V.to[0] = d_GraphRect.left();
                V.to[1] = d_GraphRect.bottom();
            
                d_ViewportMat = W;
                d_ViewportMat *=S;
                d_ViewportMat *=V;    
            }
            
            // To draw onto the graph area use something like this:
            
            	d_ViewportMat.TranslateToWin(input_data_x,input_data_y,&X,&Y);
            							
            	Painter->drawLine(LastX,LastY,X,Y);
            	LastX = X;
            	LastY = Y;
            

            The member 'TranslateToWin' will convert your input data into window coordinates that you can use to draw with. The member 'TranslateFromWin' takes window coordinates and converts to the graph (I use this to display coordinates when my mouse moves over the graph).

            K 1 Reply Last reply
            0
            • R Rondog

              You can make one yourself. You need to get the math right or it will be a mess. This is the important parts for how I did mine:

              // this is the TViewportMat that is used
              
              struct TViewportMat
              {
              	double								tx[2];
              	double								ty[2];
              	double								to[2];
              
              	TViewportMat& operator*=(const TViewportMat &rhs)
              	{
              		double							x,y,o[2];
              
              		x = tx[0] * rhs.tx[0];
              		y = ty[1] * rhs.ty[1];
              		o[0] = to[0] * rhs.tx[0] + rhs.to[0];
              		o[1] = to[1] * rhs.ty[1] + rhs.to[1];
              
              		tx[0] = x;
              		ty[1] = y;
              		to[0] = o[0];
              		to[1] = o[1];
              
              		return *this;
              	}
              
              	void TranslateToWin(const double Xd, const double Yd, int *X, int *Y) const
              	{
              		*X = static_cast<int>(Xd * tx[0] + to[0]);
              		*Y = static_cast<int>(Yd * ty[1] + to[1]);
              	}
              
              	void TranslateFromWin(const int X,const int Y,double *Xd,double *Yd) const
              	{
              		*Xd = (static_cast<double>(X) - to[0]) / tx[0];
              		*Yd = (static_cast<double>(Y) - to[1]) / ty[1];
              	}
              };
              
              
              // This updates an instance of 'TViewportMat' based on a combination of your data (the X and Y range) and the size of the widget area you plan to draw on.
              
              void TGraphWidget::CalculateViewport(void)
              {
                  double                              MinX,MaxX,MinY,MaxY,RangeX,RangeY
                  TViewportMat                        W,S,V;
               
              // find values for MinX, MaxX, MinY, MaxY from your data
              // make sure difference between Min and Max limits has a minimum value.  I use 0.00005.
              // add a margin by increasing the Min and Max limits slightly
              	
                  W.tx[0] = 1;
                  W.tx[1] = 0;
                  W.ty[0] = 0;
                  W.ty[1] = 1;
                  W.to[0] = -MinX;
                  W.to[1] = -MinY;
              
              // d_GraphRect is the rect for the area the graph occupies.
              // should be the area of the widget or at least the part the graph will occupy
              
                  S.tx[0] = (d_GraphRect.right() - d_GraphRect.left()) / (MaxX - MinX);
                  S.tx[1] = 0;
                  S.ty[0] = 0;
                  S.ty[1] = (d_GraphRect.top() - d_GraphRect.bottom()) / (MaxY - MinY);
                  S.to[0] = 0;
                  S.to[1] = 0;
              
                  V.tx[0] = 1;
                  V.tx[1] = 0;
                  V.ty[0] = 0;
                  V.ty[1] = 1;
                  V.to[0] = d_GraphRect.left();
                  V.to[1] = d_GraphRect.bottom();
              
                  d_ViewportMat = W;
                  d_ViewportMat *=S;
                  d_ViewportMat *=V;    
              }
              
              // To draw onto the graph area use something like this:
              
              	d_ViewportMat.TranslateToWin(input_data_x,input_data_y,&X,&Y);
              							
              	Painter->drawLine(LastX,LastY,X,Y);
              	LastX = X;
              	LastY = Y;
              

              The member 'TranslateToWin' will convert your input data into window coordinates that you can use to draw with. The member 'TranslateFromWin' takes window coordinates and converts to the graph (I use this to display coordinates when my mouse moves over the graph).

              K Offline
              K Offline
              kamhagh
              wrote on last edited by kamhagh
              #6

              @Rondog I've no idea what any of those mean! I rather just stick to qwt now!

              edit: after copying it to a code editor now i understand! my brain freezes when i see code without color! :D thanks!

              1 Reply Last reply
              0
              • JKSHJ JKSH

                @kamhagh said:

                **cd src/ && make -f Makefile

                How did you generate that Makefile?

                Open qwt.pro in Qt Creator and build there.

                K Offline
                K Offline
                kamhagh
                wrote on last edited by kamhagh
                #7

                @JKSH I get this when i use Qt Creator:
                :-1: error: The Qt version is invalid: Qt version is not properly installed, please run make install
                My qt creator version is 3.1.2 (based on Qt 3.2.1) its old but i had problems downloading the new version after they changed the website

                and i just ran the .run file i downloaded from the website when i installed it

                JKSHJ 1 Reply Last reply
                0
                • K kamhagh

                  @JKSH I get this when i use Qt Creator:
                  :-1: error: The Qt version is invalid: Qt version is not properly installed, please run make install
                  My qt creator version is 3.1.2 (based on Qt 3.2.1) its old but i had problems downloading the new version after they changed the website

                  and i just ran the .run file i downloaded from the website when i installed it

                  JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #8

                  @kamhagh said:

                  @JKSH I get this when i use Qt Creator:
                  :-1: error: The Qt version is invalid: Qt version is not properly installed, please run make install

                  How do you write Qt apps if your installation is broken?

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  K 2 Replies Last reply
                  0
                  • JKSHJ JKSH

                    @kamhagh said:

                    @JKSH I get this when i use Qt Creator:
                    :-1: error: The Qt version is invalid: Qt version is not properly installed, please run make install

                    How do you write Qt apps if your installation is broken?

                    K Offline
                    K Offline
                    kamhagh
                    wrote on last edited by kamhagh
                    #9

                    @JKSH
                    I've no idea! All i did was downloading the lastest qt from the website (at the time it was 5.3.1) and runing the .run file from terminal! thats it! i've been programming without any problems since then!

                    1 Reply Last reply
                    0
                    • JKSHJ JKSH

                      @kamhagh said:

                      @JKSH I get this when i use Qt Creator:
                      :-1: error: The Qt version is invalid: Qt version is not properly installed, please run make install

                      How do you write Qt apps if your installation is broken?

                      K Offline
                      K Offline
                      kamhagh
                      wrote on last edited by
                      #10

                      @JKSH Oh sorry, i get that when i try to compile it, not when i start qt creator, it actually starts without any errors!

                      JKSHJ 1 Reply Last reply
                      0
                      • K kamhagh

                        @JKSH Oh sorry, i get that when i try to compile it, not when i start qt creator, it actually starts without any errors!

                        JKSHJ Offline
                        JKSHJ Offline
                        JKSH
                        Moderators
                        wrote on last edited by
                        #11

                        @kamhagh said:

                        @JKSH Oh sorry, i get that when i try to compile it, not when i start qt creator, it actually starts without any errors!

                        Ok, then compile qwt.pro the same way as how you compile your other Qt projects..

                        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                        K 1 Reply Last reply
                        0
                        • JKSHJ JKSH

                          @kamhagh said:

                          @JKSH Oh sorry, i get that when i try to compile it, not when i start qt creator, it actually starts without any errors!

                          Ok, then compile qwt.pro the same way as how you compile your other Qt projects..

                          K Offline
                          K Offline
                          kamhagh
                          wrote on last edited by kamhagh
                          #12

                          @JKSH i press the run button and it gives me this! (with the file open and the project configured)

                          My Qt creator starts without any errors, once I open the file you mentioned in Qt Creator it asks me to configure it, so I press configure and run it, then it gives me the error I posted before.

                          1 Reply Last reply
                          0
                          • K Offline
                            K Offline
                            kamhagh
                            wrote on last edited by kamhagh
                            #13

                            After re unpacking the package it now works! let me check the installing page to see what to do next!
                            Thanks!

                            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