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

How to include .txt on Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
196 Posts 11 Posters 134.9k 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 Payx

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

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on 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 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
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on 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 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
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on 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 last edited by
              #52

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

              mrjjM 1 Reply Last reply
              0
              • P Payx

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

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on 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
                • P Offline
                  P Offline
                  Payx
                  wrote on last edited by
                  #54

                  yes but i can't know exactly, thats why i put 100.

                  The things i want its the minimum of all the value

                  like a function who calcule all diffBlue+diffRed+diffGreen
                  and return me the minimum

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Payx
                    wrote on last edited by
                    #55
                    #include "mainwindow.h"
                    #include "ui_mainwindow.h"
                    #include <QPixmap>
                    #include <QImage>
                    #include <QFileDialog>
                    #include <QColor>
                    #include <QPoint>
                    #include <QSize>
                    #include <iostream>
                    using namespace std;
                    
                    
                    QColor Couleurdominante(const QImage& image, const QPoint& topLeft, const QSize& rectSize);
                    void Remplissage(QImage& image, const QPoint& topLeft, const QSize& rectSize, const QColor& colour);
                    
                    
                    MainWindow::MainWindow(QWidget *parent) :
                    	QMainWindow(parent),
                    	ui(new Ui::MainWindow)
                    {
                    		ui->setupUi(this);
                    
                    }
                    
                    
                    MainWindow::~MainWindow()
                    {
                    	delete ui;
                    }
                    
                    
                    
                    
                    void MainWindow::on_push_clicked()
                    {
                    	QString fileName = QFileDialog::getOpenFileName(this,
                    	tr("Open Image"), "/", tr("Image Files (*.png *.jpg *.bmp)"));
                    	QPixmap pix(fileName);
                    	ui->label->setPixmap(pix);
                    	const QSize s = pix.size();
                    	pixi = QImage(pix.toImage());
                    
                    	ui->label_2->setText( "Size: " + QString::number(s.width()) +" "+ QString::number(s.height()) );
                    
                    }
                    
                    void MainWindow::on_push2_clicked()
                    {
                    
                    
                    	for (int i=0;i<pixi.width();i+=z){
                    						 for (int j=0;j<pixi.height();j+=z){
                    							 k=k+0.06;
                    							Remplissage(pixi,QPoint(i,j),QSize(z,z),Couleurdominante(pixi,QPoint(i,j),QSize(z,z)));
                    
                    		}
                    	}
                    
                    	pixa=QPixmap::fromImage(pixi);
                    	ui->label_3->setPixmap(pixa);
                    	float a = k - 0.06*z;
                    	ui->label_4->setText(QString::number(a));
                    
                    }
                    
                    
                    
                    
                    void Remplissage(QImage& image, const QPoint& topLeft, const QSize& rectangle, const QColor& colour) {
                    
                    	int maxX = topLeft.x() + rectangle.width();
                    	int maxY = topLeft.y() + rectangle.height();
                    
                    	for(int x = topLeft.x(); x < maxX; ++x) {
                    		for(int y = topLeft.y(); y < maxY; ++y) {
                    			image.setPixelColor(x, y, colour);
                    			QMapIterator<QRgb, CostInfo>i;
                    			while (i.hasNext()) {
                    				i.next();
                    				QColor BaseColor( i.key() );
                    				if (Costs.contains( colour.rgb() ) || IsCloseColor(BaseColor, colour) )  {
                    					CostInfo& ci = Costs[colour.rgb()];
                    					int Cost = ci.Cost;
                    					QPixmap pix( ci.ImageName );
                    				}
                    
                    		}			}
                    	}
                    }
                    
                    
                    QColor Couleurdominante(const QImage & image,const QPoint & topLeft, const QSize & rectangle)
                    {
                    		int rouge = 0, vert = 0, bleue = 0;
                    
                    		int  X = topLeft.x() + rectangle.width();
                    		int  Y = topLeft.y() + rectangle.height();
                    
                    		for (int y = topLeft.y(); y < Y; y++)  {
                    				for (int x = topLeft.x(); x < X; x++)   {
                    						QRgb pixel = image.pixel(x, y);
                    
                    						rouge += qRed(pixel);
                    						vert += qGreen(pixel);
                    						bleue += qBlue(pixel);
                    				}
                    		}
                    
                    		int n = rectangle.width() * rectangle.height();
                    
                    		Q_ASSERT(n);
                    		if (n <= 0)
                    				return Qt::black;
                    
                    		return QColor(rouge / n, vert / n, bleue / n);
                    }
                    
                    
                    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;
                    
                    
                    	}
                    }
                    
                    void MainWindow::on_verticalSlider_sliderMoved(int position)
                    {
                    	ui->verticalSlider->setRange(1,50);
                    		z=position;
                    }
                    

                    It said that CostInfo, Costs are not declared

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

                      Maybe you use it above where you define it or maybe u didnt show it how CostInfo is defined.

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        Payx
                        wrote on last edited by
                        #57

                        I defined my QMap here :

                        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 }},
                        };
                        

                        And this is a function call no ?

                        QMapIterator<QRgb, CostInfo>i;
                        
                        1 Reply Last reply
                        0
                        • mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #58

                          Hi
                          And where is the definition for CostInfo ?

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            Payx
                            wrote on last edited by
                            #59

                            i do not know, i thought CostInfo is the cost near the picture so i didnt needed to defined it no ?

                            FlotisableF 1 Reply Last reply
                            0
                            • P Payx

                              i do not know, i thought CostInfo is the cost near the picture so i didnt needed to defined it no ?

                              FlotisableF Offline
                              FlotisableF Offline
                              Flotisable
                              wrote on last edited by
                              #60

                              @Payx
                              the compiler only knows the fundamental types or types defined.
                              so you need to define CostInfo or compiler will give you an error.

                              P 1 Reply Last reply
                              0
                              • FlotisableF Flotisable

                                @Payx
                                the compiler only knows the fundamental types or types defined.
                                so you need to define CostInfo or compiler will give you an error.

                                P Offline
                                P Offline
                                Payx
                                wrote on last edited by
                                #61

                                @Flotisable Thank you,

                                so i have to define CostInfo as an int ?

                                FlotisableF 1 Reply Last reply
                                0
                                • P Payx

                                  @Flotisable Thank you,

                                  so i have to define CostInfo as an int ?

                                  FlotisableF Offline
                                  FlotisableF Offline
                                  Flotisable
                                  wrote on last edited by Flotisable
                                  #62

                                  @Payx
                                  in your case, one of the value you give is { "://fraise.png", 10 }, which is composed of a string and a integer

                                  it seems CostInfo should look like this

                                  struct CostInfo
                                  {
                                    QString imageName;
                                    int     cost;
                                  };
                                  
                                  1 Reply Last reply
                                  1
                                  • P Offline
                                    P Offline
                                    Payx
                                    wrote on last edited by
                                    #63

                                    Okay understood how it works now.

                                    Why it say that "Costs" is not declared, it is the name of the QMap right ?

                                    mrjjM 1 Reply Last reply
                                    0
                                    • P Payx

                                      Okay understood how it works now.

                                      Why it say that "Costs" is not declared, it is the name of the QMap right ?

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

                                      @Payx
                                      Yes Costs is the QMap variable.

                                      1 Reply Last reply
                                      0
                                      • P Offline
                                        P Offline
                                        Payx
                                        wrote on last edited by
                                        #65

                                        How do i declare a QMap ?

                                        i tried

                                        QMap<QRgb, CostInfo > Costs;
                                        
                                        mrjjM 1 Reply Last reply
                                        0
                                        • P Payx

                                          How do i declare a QMap ?

                                          i tried

                                          QMap<QRgb, CostInfo > Costs;
                                          
                                          mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #66

                                          @Payx
                                          Yes that is how you declare an empty QMap called Costs.

                                          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