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. How to include .txt on Qt
QtWS25 Last Chance

How to include .txt on Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
196 Posts 11 Posters 134.4k 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.
  • P Offline
    P Offline
    Payx
    wrote on 7 Dec 2016, 12:46 last edited by
    #34

    for the function IsCloseColor, its not better to return a color ? like QColor IsCloseColor();, i don't understand what we can do if we return "false" or "true"

    M 1 Reply Last reply 7 Dec 2016, 12:50
    0
    • P Payx
      7 Dec 2016, 12:46

      for the function IsCloseColor, its not better to return a color ? like QColor IsCloseColor();, i don't understand what we can do if we return "false" or "true"

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 7 Dec 2016, 12:50 last edited by
      #35

      @Payx

      It just checks if the color is "close " to base color
      No reason to return color ?
      we say
      if (Costs.contains( colour.rgb() ) || IsCloseColor(BaseColor, colour) )

      So if we have direct match OR
      the colour is close to BaseColor then we think its ok.

      1 Reply Last reply
      1
      • P Offline
        P Offline
        Payx
        wrote on 21 Dec 2016, 14:06 last edited by Payx
        #36

        Okay thank you,

        i have

        diffBlue+diffRed+diffGreen< 100
        

        but if many colors correspond ?
        it can return many colors no ?

        M 1 Reply Last reply 21 Dec 2016, 14:19
        0
        • P Payx
          21 Dec 2016, 14:06

          Okay thank you,

          i have

          diffBlue+diffRed+diffGreen< 100
          

          but if many colors correspond ?
          it can return many colors no ?

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 21 Dec 2016, 14:19 last edited by mrjj
          #37

          @Payx
          No it cant..
          IsCloseColor tells if 2 colors are close. It return true/false.
          it dont return any color. it tells you if they color u have "in the hand" matches the
          base color given.
          You already have the color (colour var) so no reason to return it.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Payx
            wrote on 21 Dec 2016, 14:21 last edited by
            #38

            So it cant be possible to have 2 colors who is <100 ?

            M 1 Reply Last reply 21 Dec 2016, 14:23
            0
            • P Payx
              21 Dec 2016, 14:21

              So it cant be possible to have 2 colors who is <100 ?

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 21 Dec 2016, 14:23 last edited by mrjj
              #39

              @Payx
              ofc, just compare 2 times or more times. Once pr color.
              IsCloseColor(BaseColor, col1)
              IsCloseColor(BaseColor, col2)
              IsCloseColor(BaseColor, col3)
              ....

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Payx
                wrote on 21 Dec 2016, 14:26 last edited by mrjj
                #40

                So if i have like 27 colors, i have to do 27 function ?

                M 1 Reply Last reply 21 Dec 2016, 14:30
                0
                • P Payx
                  21 Dec 2016, 14:26

                  So if i have like 27 colors, i have to do 27 function ?

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 21 Dec 2016, 14:30 last edited by
                  #41

                  @Payx
                  No. use a list (of colors) and loop over it, checking each.

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Payx
                    wrote on 21 Dec 2016, 14:36 last edited by
                    #42

                    Okay, so it's useless to write :

                    bool IsCloseColor( QColor c1, QColor c2 ) {
                    	int diffRed   = Math.abs(c1.red() - c2.red());
                    	int diffGreen = Math.abs(c1.green() - c2.green());
                    	int diffBlue  = Math.abs(c1.blue()  - c2.blue());
                    
                    	if (diffBlue+diffRed+diffGreen< 100){	/
                    		return true;.
                    		else
                    				return false;
                    
                    
                    	}
                    }
                    
                    

                    So if i understood well the "<100" is now useless. Can't we just return the color who have the minimum diffBlue+diffRed+diffGreen ?

                    M 1 Reply Last reply 21 Dec 2016, 14:48
                    0
                    • P Payx
                      21 Dec 2016, 14:36

                      Okay, so it's useless to write :

                      bool IsCloseColor( QColor c1, QColor c2 ) {
                      	int diffRed   = Math.abs(c1.red() - c2.red());
                      	int diffGreen = Math.abs(c1.green() - c2.green());
                      	int diffBlue  = Math.abs(c1.blue()  - c2.blue());
                      
                      	if (diffBlue+diffRed+diffGreen< 100){	/
                      		return true;.
                      		else
                      				return false;
                      
                      
                      	}
                      }
                      
                      

                      So if i understood well the "<100" is now useless. Can't we just return the color who have the minimum diffBlue+diffRed+diffGreen ?

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 21 Dec 2016, 14:48 last edited by
                      #43

                      @Payx
                      The < 100 is the factor on How close the color was to the Base Color.
                      So i do not understand u think its useless.

                      How else would u compare them?

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        Payx
                        wrote on 21 Dec 2016, 18:09 last edited by
                        #44

                        u said "do a list", instead of write ...<100, we can do a "for" and "return" the minimal "diffBlue+diffRed+diffGreen" or the all color no ?

                        jsulmJ 1 Reply Last reply 22 Dec 2016, 05:44
                        0
                        • P Payx
                          21 Dec 2016, 18:09

                          u said "do a list", instead of write ...<100, we can do a "for" and "return" the minimal "diffBlue+diffRed+diffGreen" or the all color no ?

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 22 Dec 2016, 05:44 last edited by
                          #45

                          @Payx If you want to return the closest color from a list then you need to write a function similar to IsCloseColor. You iterate over the list, calculate the diff and store the color with the smallest diff and its diff in local variables, then return the color from that local variable.

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

                          1 Reply Last reply
                          2
                          • P Offline
                            P Offline
                            Payx
                            wrote on 22 Dec 2016, 16:30 last edited by
                            #46

                            I learn how to browse number (from 0 to 50) but how to browse a list ?

                            M 1 Reply Last reply 22 Dec 2016, 16:40
                            0
                            • P Payx
                              22 Dec 2016, 16:30

                              I learn how to browse number (from 0 to 50) but how to browse a list ?

                              M Offline
                              M Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 22 Dec 2016, 16:40 last edited by
                              #47

                              @Payx
                              No sure what "browse a list is"

                                  QList<QColor> ColorList;
                                  ColorList << QColor(100,100,100) << QColor(200,200,200) << QColor(0,0,100) ;
                                  for( int c=0; c < ColorList.size();c++ ) {
                                  QColor CurCol=ColorList[c]; // take from list
                                  // ... do what u want
                                  }
                              
                              1 Reply Last reply
                              0
                              • P Offline
                                P Offline
                                Payx
                                wrote on 22 Dec 2016, 19:18 last edited by
                                #48

                                like compare all the color with a for

                                you said it to me ^^

                                @Payx
                                No. use a list (of colors) and loop over it, checking each.

                                i already have this (you give it to me)

                                QMap<QRgb, CostInfo > Costs = {
                                	{ QColor(255 , 0 , 0 ).rgb(), { "://fraise.png", 10 }},
                                	{ QColor(0 , 255 , 0 ).rgb(), { "://balleverte.png", 20 }},
                                	{ QColor(0 , 0 , 255 ).rgb(), { "://ballebleue.png", 20 }},
                                	{ QColor(255 , 255 , 255 ).rgb(), { "://balleblanche.png", 20 }},
                                	{ QColor(255 , 128 , 0 ).rgb(), { "://ballepeche.png", 20 }},
                                	{ QColor(0 , 0 , 0 ).rgb(), { "://noir.png", 20 }},
                                	{ QColor(102 , 51 , 0 ).rgb(), { "://marron.png", 20 }},
                                	{ QColor(255 , 102 , 78 ).rgb(), { "://rose.png", 20 }},
                                	{ QColor(0 , 204 , 204 ).rgb(), { "://turquoise.png", 20 }},
                                	{ QColor(255 , 178 , 102 ).rgb(), { "://beige.png", 20 }},
                                	{ QColor(76 , 0 , 153 ).rgb(), { "://violet.png", 20 }},
                                	{ QColor(100 , 100 , 100 ).rgb(), { "://gris.png", 20 }},
                                };
                                
                                bool IsCloseColor( QColor c1, QColor c2 ) {
                                	int diffRed   = Math.abs(c1.red() - c2.red());
                                	int diffGreen = Math.abs(c1.green() - c2.green());
                                	int diffBlue  = Math.abs(c1.blue()  - c2.blue());
                                
                                	if (diffBlue+diffRed+diffGreen< 100){	/
                                		return true;.
                                		else
                                				return false;
                                
                                
                                	}
                                }
                                

                                the function i want to create is to browse the Qmap and pick the color who got the minimum ""diffBlue+diffRed+diffGreen< 100""

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on 22 Dec 2016, 23:09 last edited by mrjj
                                  #49

                                  Hi
                                  ok. i see. we had the code higher up.

                                  Qcolor colour; // the one you compare too. set to something...
                                  QMapIterator<QRgb, CostInfo >i(Costs);
                                  while (i.hasNext()) {
                                  i.next();
                                  QColor BaseColor( i.key() ); // the color in table
                                  if (Costs.contains( colour.rgb() ) || IsCloseColor(BaseColor, colour) ) { // directly have colour or it is < 100
                                  //// we got a match
                                  }
                                  }// while

                                  1 Reply Last reply
                                  0
                                  • P Offline
                                    P Offline
                                    Payx
                                    wrote on 24 Dec 2016, 12:41 last edited by
                                    #50

                                    Okay,

                                    but we keep the code ?

                                    because the <100 isn't good, you said we have to compare all the colors and see what colors match the best

                                    1 Reply Last reply
                                    0
                                    • M Offline
                                      M Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on 24 Dec 2016, 13:40 last edited by
                                      #51

                                      Yes ?
                                      Then change the 100.
                                      Its just a value. You should examine your color and see
                                      the value for color that you consider "The same"
                                      Maybe its need to be 80 or 110. Depends on how close
                                      the color must be for you to think its the same.

                                      1 Reply Last reply
                                      0
                                      • P Offline
                                        P Offline
                                        Payx
                                        wrote on 24 Dec 2016, 21:50 last edited by
                                        #52

                                        Yes, but correct me if i'm wrong, it could be possible that it detect many colors under 100 right ?

                                        M 1 Reply Last reply 25 Dec 2016, 08:28
                                        0
                                        • P Payx
                                          24 Dec 2016, 21:50

                                          Yes, but correct me if i'm wrong, it could be possible that it detect many colors under 100 right ?

                                          M Offline
                                          M Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on 25 Dec 2016, 08:28 last edited by
                                          #53

                                          @Payx
                                          its a value. How high or low u need it to be , depends
                                          on your application.

                                          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