How to include .txt on Qt
-
You should cleanup the casing of your variables and class member calls.
-
wrote on 29 Dec 2016, 23:32 last edited by
How clean up all ?
-
wrote on 30 Dec 2016, 06:48 last edited by Flotisable
@Payx
in your definition ofCostInfo
, your variable is namedcost
notCost
the member
hasNext
andnext
belong toQMapIterator
, notQMap::iterator
read the document of QMapIterator and QMap::iterator for more information -
wrote on 30 Dec 2016, 14:21 last edited by
So the line
QMapIterator<QRgb, CostInfo> i(Costs);
Is correct ?
""
What is a redefinition of a QMap ? because it say that i have a redefinition of ""QMap<QRgb, CostInfo > Costs"" -
Hi
I move the code around so it compiled here.
https://www.dropbox.com/s/1z7lzjk4fqwxslz/mycolortest.zip?dl=0
Also change QMapIterator to a for each loop to get rid of QMapIterator.If you get any errors from this it, please list them exactly.
-
wrote on 30 Dec 2016, 15:46 last edited by
Thanks it compile,
the problem is that my window crash when i push the boutton who execute
" Remplissage(pixi, QPoint(i, j), QSize(z, z), Couleurdominante(pixi, QPoint(i, j), QSize(z, z)));
"
^^maybe enough things to do ?
-
Well since you know what function it is, simply set a break point and single step through the code.
That way it will clearly show what line it crashes on. ;) -
wrote on 30 Dec 2016, 16:20 last edited by
It's not crash, the program run at infinity and do nothing
-
@Payx
well that will also be really clear from single stepping :) -
wrote on 30 Dec 2016, 16:59 last edited by Payx
I placed breakpoint on
for(int x = topLeft.x(); x < maxX; ++x) { for(int y = topLeft.y(); y < maxY; ++y) { image.setPixelColor(x, y, colour); foreach( QRgb key, Costs.keys() ) { QColor BaseColor( key ); if (Costs.contains( colour.rgb() ) || IsCloseColor(BaseColor, colour) ) { CostInfo& ci = Costs[colour.rgb()]; int Cost = ci.Cost; QPixmap pix( ci.ImageName ); }
because its new and before it worked.
And nothing who looks like a crash happened. So i don't understand, maybe it is just a big picture (540 * 540) and the app have difficult to do the code
EDIT : i tried to increase the rectangle size, it worked.
but dont replace the color by a picture
and it say that int cost is an unused variable
-
Hi
In the inner
CostInfo& ci = Costs[colour.rgb()];
int Cost = ci.Cost; // not used for anything
QPixmap pix( ci.ImageName ); // not used for anything
}it was just for getting the data from the Costs qmap.
You still need to code what ever you want to do with it :)
Currently it just check if color is a match and even if yes, then nothing. -
wrote on 30 Dec 2016, 18:08 last edited by Payx
so if i understood well
int Cost = ci.Cost; /// the Cost in my Qmap
QPixmap pix( ci.ImageName ); /// the picture into a PixmapThe problem is that the rectangle that i use to calcul the DominantColor isn't a Label or something, so how can i replace a picture into a virtual rectangle ?
-
so if i understood well
int Cost = ci.Cost; /// the Cost in my Qmap
QPixmap pix( ci.ImageName ); /// the picture into a PixmapThe problem is that the rectangle that i use to calcul the DominantColor isn't a Label or something, so how can i replace a picture into a virtual rectangle ?
@Payx
Yes those are the values from the qmap.- so how can i replace a picture into a virtual rectangle
Sorry but Im not sure what kind of operation you want to do.
For each dominĂ¡nt color for an area. you want to paint all of that area
with this color? Like paint 0,0,40,40 with same color. ? -
wrote on 30 Dec 2016, 22:30 last edited by
My program already do that :
but what i want is that for each rectangle that my picture have, it will replace this rectangle of color by a picture in my QMap (like if the rectangle's color is near the red, it will replace by the picture fraise.png and add a Cost)
-
My program already do that :
but what i want is that for each rectangle that my picture have, it will replace this rectangle of color by a picture in my QMap (like if the rectangle's color is near the red, it will replace by the picture fraise.png and add a Cost)
@Payx
You mean that the red squares would be pictures instead?
The painter has drawPixmap
http://doc.qt.io/qt-5/qpainter.html#drawPixmap
You can fit the image to the rect. -
wrote on 30 Dec 2016, 23:04 last edited by
All square would be picture, the picture depends of the color.
If its red we see in the QMap that the picture is fraise.png
if its green -> balle verte.pngi think i dont need "QRectF target" or "source"
because i have already this
for(int x = topLeft.x(); x < maxX; ++x) { for(int y = topLeft.y(); y < maxY; ++y)
when im on the for i'm already in the square.
-
ok. that sounds fine.
I assume you need to scale the pictures down to fit in the
area. ?
You can use scaled function.QPixmap scaledPix = pix.scaled( WIDTH, HEIGHT Qt::KeepAspectRatio, Qt::SmoothTransformation ); painter.drawPixmap(QPoint(), scaledPix);
-
wrote on 31 Dec 2016, 14:34 last edited by Payx
So i have to rezise the picture or it will do automaticaly ?
i don't understand what the function do
-
No, you will have to resize it, else it will be exactly as in the file.( I assume too big)
the scaled function returns a copy of the pixmap that is scaled to
WIDTH, HEIGHT. so it will fit in your area. -
wrote on 31 Dec 2016, 15:22 last edited by
so if my rectangle is 8*8 tell me if it's correct :
QPixmap scaledPix = pix.scaled( 8, 8 Qt::KeepAspectRatio, Qt::SmoothTransformation ); painter.drawPixmap(QPoint(i,j), scaledPix);
just that ?
93/196