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. Create a matrix from a .csv file

Create a matrix from a .csv file

Scheduled Pinned Locked Moved Solved General and Desktop
140 Posts 2 Posters 51.2k 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.
  • A Offline
    A Offline
    AliM93
    wrote on 31 May 2020, 00:28 last edited by AliM93
    #44

    done! thanks, now we have to modify the paintevent in order to show the grid, right?

    M 1 Reply Last reply 31 May 2020, 00:30
    1
    • A AliM93
      31 May 2020, 00:28

      done! thanks, now we have to modify the paintevent in order to show the grid, right?

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 31 May 2020, 00:30 last edited by
      #45

      @AliM93

      Ok, small fix.
      You data has max x,y as
      x: 14 y: 21
      so our array is one to small as we start in 0 (zero)
      so change

      const int max_x = 14;
      const int max_y = 21;

      to

      const int max_x = 15;
      const int max_y = 22;

      as else we drop some :)

      A 1 Reply Last reply 31 May 2020, 00:32
      1
      • M mrjj
        31 May 2020, 00:30

        @AliM93

        Ok, small fix.
        You data has max x,y as
        x: 14 y: 21
        so our array is one to small as we start in 0 (zero)
        so change

        const int max_x = 14;
        const int max_y = 21;

        to

        const int max_x = 15;
        const int max_y = 22;

        as else we drop some :)

        A Offline
        A Offline
        AliM93
        wrote on 31 May 2020, 00:32 last edited by
        #46

        @mrjj ok thanks

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 31 May 2020, 00:35 last edited by
          #47

          Ok next step is to add some paint code.

          So in .cpp

          void MatrixWidget::paintEvent(QPaintEvent *event)
          {
          
              QPainter p(this);
              // draw frame.
              p.drawRect(0, 0, width() - 1, height() - 1);
          
              // size of area we have. w = width , h = height , we take 2 pixles for border
              int w = width() - 2;
              int h = height() - 2;
          
              // now we find out how big each box should be which area we have  divided with how many on x and y
              int bw = w / max_x;
              int bh = h / max_y;
          
              // now we loop and drw the boxes
              for (int xi = 0; xi < max_x; ++xi) {
                  for (int yi = 0; yi < max_x; ++yi) {
                      p.drawRect( QRect( xi * bw, yi * bh, bw, bh  ) )  ;
                  }
              }
          
          }
          

          and then next we will add to some UI so we can see what it start working :)
          Teaser.
          alt text

          A 1 Reply Last reply 31 May 2020, 00:40
          0
          • M mrjj
            31 May 2020, 00:35

            Ok next step is to add some paint code.

            So in .cpp

            void MatrixWidget::paintEvent(QPaintEvent *event)
            {
            
                QPainter p(this);
                // draw frame.
                p.drawRect(0, 0, width() - 1, height() - 1);
            
                // size of area we have. w = width , h = height , we take 2 pixles for border
                int w = width() - 2;
                int h = height() - 2;
            
                // now we find out how big each box should be which area we have  divided with how many on x and y
                int bw = w / max_x;
                int bh = h / max_y;
            
                // now we loop and drw the boxes
                for (int xi = 0; xi < max_x; ++xi) {
                    for (int yi = 0; yi < max_x; ++yi) {
                        p.drawRect( QRect( xi * bw, yi * bh, bw, bh  ) )  ;
                    }
                }
            
            }
            

            and then next we will add to some UI so we can see what it start working :)
            Teaser.
            alt text

            A Offline
            A Offline
            AliM93
            wrote on 31 May 2020, 00:40 last edited by AliM93
            #48

            @mrjj thanks also for comments, so i can better follow the flow. but sorry i have to include QPainter somewhere? yes solved!

            M 1 Reply Last reply 31 May 2020, 00:43
            1
            • A AliM93
              31 May 2020, 00:40

              @mrjj thanks also for comments, so i can better follow the flow. but sorry i have to include QPainter somewhere? yes solved!

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 31 May 2020, 00:43 last edited by mrjj
              #49

              @AliM93
              Yep, need includes.

              I hope comments are enough to understand it.
              its just calculating how big each box should when we have max_x and max_y and some area ( the widgets area)

              Shall we try to add it and UI and see something?
              I want to show you a Creator feature called Promotion that makes it easy to use such custom control.

              (note i bumped your upvotes so you should be able to post faster now)

              A 1 Reply Last reply 31 May 2020, 00:44
              0
              • M mrjj
                31 May 2020, 00:43

                @AliM93
                Yep, need includes.

                I hope comments are enough to understand it.
                its just calculating how big each box should when we have max_x and max_y and some area ( the widgets area)

                Shall we try to add it and UI and see something?
                I want to show you a Creator feature called Promotion that makes it easy to use such custom control.

                (note i bumped your upvotes so you should be able to post faster now)

                A Offline
                A Offline
                AliM93
                wrote on 31 May 2020, 00:44 last edited by
                #50

                @mrjj sure! the only thing is, as you can image from my images, i'm working into a bigger file, and when i run the app i have also a main_window.ui. so i have to link all the things to that. is it possilbe, isn'it it?

                M 1 Reply Last reply 31 May 2020, 00:45
                0
                • A AliM93
                  31 May 2020, 00:44

                  @mrjj sure! the only thing is, as you can image from my images, i'm working into a bigger file, and when i run the app i have also a main_window.ui. so i have to link all the things to that. is it possilbe, isn'it it?

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 31 May 2020, 00:45 last edited by
                  #51

                  @AliM93
                  yes, i though we add it to your main ui to see its working ?

                  Its same project still, correct ?

                  A 1 Reply Last reply 31 May 2020, 00:48
                  0
                  • M mrjj
                    31 May 2020, 00:45

                    @AliM93
                    yes, i though we add it to your main ui to see its working ?

                    Its same project still, correct ?

                    A Offline
                    A Offline
                    AliM93
                    wrote on 31 May 2020, 00:48 last edited by
                    #52

                    @mrjj yes, but in the final project i need to add to a QDialog which starts after i click a button on the main_window, but i hope it is not a big problem, right? anyway we can use a pushbutton clicked to show this now?

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 31 May 2020, 00:50 last edited by
                      #53

                      Yes you can add to a dialog the same way as to any other UI :)

                      To use your custom widget.
                      Go to your main window ui file and open it
                      place a normal Qwidget on the form
                      RIGHt click it
                      alt text
                      and choose promote to

                      Then in the new window , fillin the class name

                      alt text
                      nake SURE to spell it as shown in file!
                      MatrixWidget for "class name"
                      Case matters!

                      now press ADD
                      then Press Promote.

                      When you run the app, our custom widget will be shown instead of the plain one we added.

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        AliM93
                        wrote on 31 May 2020, 00:51 last edited by
                        #54

                        my main_window is still polupated

                        M 1 Reply Last reply 31 May 2020, 00:53
                        0
                        • A Offline
                          A Offline
                          AliM93
                          wrote on 31 May 2020, 00:52 last edited by AliM93
                          #55
                          This post is deleted!
                          1 Reply Last reply
                          0
                          • A AliM93
                            31 May 2020, 00:51

                            my main_window is still polupated

                            M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 31 May 2020, 00:53 last edited by
                            #56

                            @AliM93

                            add to the dialog then :)
                            Its 100% the same way.
                            Dont matter which UI.

                            So lets just use the dialog.

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              AliM93
                              wrote on 31 May 2020, 00:54 last edited by AliM93
                              #57

                              ok, so what i have to do? Add a normal QWidget to may main_window

                              M 2 Replies Last reply 31 May 2020, 00:54
                              0
                              • A AliM93
                                31 May 2020, 00:54

                                ok, so what i have to do? Add a normal QWidget to may main_window

                                M Offline
                                M Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on 31 May 2020, 00:54 last edited by
                                #58

                                @AliM93

                                open UI file for dialog and promote it as shown.
                                This Creator feature will then allow us to use our new custom widget without adding it from code.

                                1 Reply Last reply
                                0
                                • A AliM93
                                  31 May 2020, 00:54

                                  ok, so what i have to do? Add a normal QWidget to may main_window

                                  M Offline
                                  M Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on 31 May 2020, 00:55 last edited by
                                  #59

                                  @AliM93 said in Create a matrix from a .csv file:

                                  Add a normal QWidget to may main_window

                                  No, not if you want to use the dialog.

                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    AliM93
                                    wrote on 31 May 2020, 00:56 last edited by
                                    #60

                                    yes but which dialog i have to open? i don't have in this file.. can i add?

                                    M 1 Reply Last reply 31 May 2020, 00:56
                                    0
                                    • A AliM93
                                      31 May 2020, 00:56

                                      yes but which dialog i have to open? i don't have in this file.. can i add?

                                      M Offline
                                      M Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on 31 May 2020, 00:56 last edited by
                                      #61

                                      @AliM93
                                      Ohh, you dont have dialog yet ?
                                      Lets add new blank one.
                                      Sec. shots.

                                      A 1 Reply Last reply 31 May 2020, 00:57
                                      0
                                      • M mrjj
                                        31 May 2020, 00:56

                                        @AliM93
                                        Ohh, you dont have dialog yet ?
                                        Lets add new blank one.
                                        Sec. shots.

                                        A Offline
                                        A Offline
                                        AliM93
                                        wrote on 31 May 2020, 00:57 last edited by
                                        #62

                                        @mrjj no because i have the maxi project, and i split to a little one, then i will integrate

                                        1 Reply Last reply
                                        0
                                        • M Offline
                                          M Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on 31 May 2020, 01:00 last edited by
                                          #63

                                          Again, select the File New as when we made the widget.

                                          alt text

                                          Choose Designer Form class

                                          Then choose a dialog

                                          alt text

                                          Give it a good name
                                          alt text

                                          Press NExt, NExt

                                          Now you have this and you add a QWidget to it and promote it.
                                          alt text

                                          A 1 Reply Last reply 31 May 2020, 01:06
                                          0

                                          53/140

                                          31 May 2020, 00:50

                                          • Login

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