Paint Rect visible on Drag to crop image coordinate
PS: my first QPainter not run...
I made a extra QWidget scaled on ratio image... to display a red rect to crop a simple image....
but now this paint is visible only if i resize the widged :-(
http://ppk.ciz.ch/qt_c++/crop_selecter.png
Or must i attach other event on drag???
I wand this rect visible on drag mesure to select crop image ....
Code:
{
if (display.isNull()) {
qDebug() << "### display pixmap broken!!!! " << display.isNull();
return;
}
qDebug() << "### paintEvent go starter...... ";
Load_Actual_Desktop(); /* widget size setting e resolution X11 */
int hi_now = widgetSize.height();
int wi_now = widgetSize.width();
picscaled = display.scaled(wi_now,hi_now,Qt::KeepAspectRatio); /* scaled to widget displayer */
QSize actual_result
= picscaled.
size();
/* get */ Ratio_On_Work(actual_result);
painter.drawPixmap(0,0,picscaled);
selectionText
= QString("Image %1 x %2").
arg(actual_result.
width()).
arg(actual_result.
height());
int stringWidth = fm.width(selectionText);
int stringHeight = fm.ascent();
const int TEXT_MARGIN = 4;
/* color to pen */
QColor fillrectcolor
= Qt
::red;
int textX = 0;
int textY = 0;
/* display rect mesure image crop !!! */
QPoint topLeft
( QMIN
(mousePRESSPoint.
x(), mouseRELEASEPoint.
x()),
QMIN(mousePRESSPoint.y(), mouseRELEASEPoint.y()) );
QPoint bottomRight
( QMAX
(mousePRESSPoint.
x(), mouseRELEASEPoint.
x()),
QMAX(mousePRESSPoint.y(), mouseRELEASEPoint.y()) );
QRect selectionIMAGE
( topLeft, bottomRight
);
/* display rect mesure image crop !!! */
/* display rect mesure text crop !!! */
QPoint topLeftT
( QMIN
(mousePRESSPoint.
x(), mouseRELEASEPoint.
x()) + TEXT_MARGIN ,
QMIN(mousePRESSPoint.y(), mouseRELEASEPoint.y()) + TEXT_MARGIN );
QPoint bottomRightT
( QMAX
(mousePRESSPoint.
x(), mouseRELEASEPoint.
x()) + TEXT_MARGIN ,
QMAX(mousePRESSPoint.y(), mouseRELEASEPoint.y()) + TEXT_MARGIN );
QRect selectionTEXT
( topLeftT, bottomRightT
);
/* display rect mesure text crop !!! */
pen.setStyle( Qt::SolidLine );
pen.setCapStyle( Qt::RoundCap );
pen.setColor( fillrectcolor );
pen.setWidth( 2 );
/* display rect to crop image !!! */
painter.setPen( pen);
painter.drawRect(selectionIMAGE);
/* display rect to crop image !!! */
/* display text image ratio text on crop image !!! */
pen.setColor( textColor );
painter.setPen( pen);
/* display text image ratio text on crop image !!! */
painter.drawText(selectionTEXT,selectionText);
//////// Show_Actual_Params(); /* debug display coordinate all */
}
{
qDebug() << "### mousePressEvent -> " << e->x() << "x" << e->y();
mousePRESSPoint = e->pos();
}
{
qDebug() << "### mouseReleaseEvent -> " << e->x() << "x" << e->y();
mouseRELEASEPoint = e->pos();
}
{
qDebug() << "### mouseReleaseEvent -> " << e->x() << "x" << e->y();
mouseMOVEPoint = e->pos();
}
Re: Paint Rect visible on Drag to crop image coordinate
What exactly is the question? Could you prepare a minimal compilable example reproducing the problem?
Re: Paint Rect visible on Drag to crop image coordinate
Quote:
Originally Posted by
wysota
What exactly is the question? Could you prepare a minimal compilable example reproducing the problem?
Here is a example wo reproducing .... the display widged to work on operation crop image...
main.h
main.cpp
image_operator.h
image_operator.cpp
test.png
qt profile
http://ppk.ciz.ch/qt_c++/imagegrop.zip 300kb (one image 280kb inside)
I found so mach sample from paint on qt wiki book or other .... never found a sample to simply crop or cut a part of a image....
I wand to paint the red rectange on the drag process to display live on the selected rect to crop.... (same as gimp)
not only on release mouse.....
The target from this widged is only to find ...
QImage* cropImage( QString filename, QPoint topLeft, QPoint bottomRight )
I take sample base from http://albumshaper.sourceforge.net/
http://ppk.ciz.ch/qt_c++/image_crop/ selectionInterface.cpp
Re: Paint Rect visible on Drag to crop image coordinate
If you want to cut out part of an image (I assume this is your goal), just create a new image and paint a section of the previous one on the new one.
Take a look at QPainter::drawImage that takes the source rectangle as its argument.
Re: Paint Rect visible on Drag to crop image coordinate
Quote:
Originally Posted by
wysota
If you want to cut out part of an image (I assume this is your goal), just create a new image and paint a section of the previous one on the new one.
Take a look at
QPainter::drawImage that takes the source rectangle as its argument.
Yes the final target is Crop the image....:)
..... before i Want to display the -> painter.drawRect(selectionIMAGE); :(
on event Move Mouse pull down rectangle the action to select the Crop ...
Now my script display only the rectangle on resize .... mouse Out.....
mouseReleaseEvent(QMouseEvent *e)
Not on drag move action ... is here other event?
Code:
//==============================================
{
//load original image
//convert to 32-bit depth if necessary
if( origImage.depth() < 32 ) { origImage = origImage.convertDepth( 32, Qt::AutoColor ); }
//construct cropped image
QImage* croppedImage
= new QImage(bottomRight.
x() - topLeft.
x() + 1,
bottomRight.y() - topLeft.y() + 1,
origImage.depth());
//iterate over each selected scanline
int xOrig, yOrig;
int xCropped, yCropped;
uchar *origScanLine, *croppedScanLine;
for( yOrig=topLeft.y(),yCropped=0; yOrig<=bottomRight.y(); yOrig++, yCropped++)
{
//iterate over each selected pixel in scanline
origScanLine = origImage.scanLine(yOrig);
croppedScanLine = croppedImage->scanLine(yCropped);
for( xOrig=topLeft.x(),xCropped=0; xOrig<=bottomRight.x(); xOrig++,xCropped++)
{
//copy pixel color from original image to cropped image
*((QRgb*)croppedScanLine+xCropped) = *((QRgb*)origScanLine+xOrig);
}
}
//return pointer to cropped image
return croppedImage;
}
Re: Paint Rect visible on Drag to crop image coordinate
Maybe it will be easier if you use QRubberBand?
Re: Paint Rect visible on Drag to crop image coordinate
Quote:
Originally Posted by
jacek
Crasch app maybe QRubberBand and paintEvent is not able to live together....
&& i wand to display text pixel size to crop.... on top of rectange
i test now to split action & switch paint mode...
&& QWidget::paintEngine ()
Quote:
typedef enum
{
DRAW_SELECTION,
MOVE_SELECTION,
MOVE_TOP_LEFT_CORNER,
MOVE_TOP_RIGHT_CORNER,
MOVE_BOTTOM_LEFT_CORNER,
MOVE_BOTTOM_RIGHT_CORNER,
MOVE_LEFT_SIDE,
MOVE_RIGHT_SIDE,
MOVE_TOP_SIDE,
MOVE_BOTTOM_SIDE,
SCALE_SELECTION,
DRAW_LINE,
KEYBOARD_CTRL,
NO_EFFECT
} DRAG_MODE;
Re: Paint Rect visible on Drag to crop image coordinate
I have it .... :) :) :) the solution is only repaint on mouseMoveEvent && define each DRAG_MODE
on widged....
Code:
typedef enum
{
DRAW_SELECTION,
SCALE_SELECTION,
DRAW_LINE,
DRAW_START,
NO_EFFECT
} DRAG_MODE;
{
currentDragMode = DRAW_LINE;
mouseRELEASEPoint = e->pos();
if (display.isNull()) {
return;
}
/* remove draw lines */
Load_Actual_Desktop(); /* widget size setting e resolution X11 */
int hi_now = widgetSize.height();
int wi_now = widgetSize.width();
QPoint bottomRight
( widgetSize.
width() , widgetSize.
height() );
QRect areanow
( topLeft, bottomRight
);
repaint(areanow);
}
if ( currentDragMode == DRAW_SELECTION || currentDragMode == DRAW_LINE ) {
OneWorkImage = selectionIMAGE;
pen.setWidth( bordershade );
pen.setColor( shapepicture );
painter.setPen( pen);
painter.drawRect(selectionOutIMAGE);
/* ................... draw rectangle or only image display on the Zoom Widged && resizable ....*/
source & PrtScn avaiable....
http://www.qtforum.de/forum/viewtopic.php?t=3885
Re: Paint Rect visible on Drag to crop image coordinate
Please try to express yourself with simple and full sentences, without "...", abreviations, images or code that distract the reader from the topic of your post - especially if you're not sure of your English language skills. Using such constructions makes your post barely readable and hardly understandable. So does including a large amount of code that doesn't add anything to the conversation. If you have to paste some of your code, please remove parts that are not important.
I have to say that after reading this thread a few times I still don't know what the problem was. The thread title suggests problems with cropping an image, but the thread content implies something completely different.