Results 1 to 9 of 9

Thread: Paint Rect visible on Drag to crop image coordinate

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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 :-(



    Or must i attach other event on drag???

    I wand this rect visible on drag mesure to select crop image ....

    Qt Code:
    1. void Image_Operator::paintEvent(QPaintEvent *e)
    2. {
    3.  
    4. if (display.isNull()) {
    5. qDebug() << "### display pixmap broken!!!! " << display.isNull();
    6. return;
    7. }
    8. qDebug() << "### paintEvent go starter...... ";
    9. Load_Actual_Desktop(); /* widget size setting e resolution X11 */
    10. int hi_now = widgetSize.height();
    11. int wi_now = widgetSize.width();
    12. picscaled = display.scaled(wi_now,hi_now,Qt::KeepAspectRatio); /* scaled to widget displayer */
    13. QSize actual_result = picscaled.size(); /* get */
    14. Ratio_On_Work(actual_result);
    15. QPainter painter(this);
    16. painter.drawPixmap(0,0,picscaled);
    17. QString selectionText;
    18. selectionText = QString("Image %1 x %2").arg(actual_result.width()).arg(actual_result.height());
    19.  
    20. QFontMetrics fm( this->font() );
    21. int stringWidth = fm.width(selectionText);
    22. int stringHeight = fm.ascent();
    23. const int TEXT_MARGIN = 4;
    24.  
    25. /* color to pen */
    26. QColor textColor = Qt::black;
    27. QColor fillrectcolor = Qt::red;
    28.  
    29. int textX = 0;
    30. int textY = 0;
    31.  
    32. /* display rect mesure image crop !!! */
    33. QPoint topLeft( QMIN(mousePRESSPoint.x(), mouseRELEASEPoint.x()),
    34. QMIN(mousePRESSPoint.y(), mouseRELEASEPoint.y()) );
    35. QPoint bottomRight( QMAX(mousePRESSPoint.x(), mouseRELEASEPoint.x()),
    36. QMAX(mousePRESSPoint.y(), mouseRELEASEPoint.y()) );
    37. QRect selectionIMAGE( topLeft, bottomRight );
    38. /* display rect mesure image crop !!! */
    39. /* display rect mesure text crop !!! */
    40. QPoint topLeftT( QMIN(mousePRESSPoint.x(), mouseRELEASEPoint.x()) + TEXT_MARGIN ,
    41. QMIN(mousePRESSPoint.y(), mouseRELEASEPoint.y()) + TEXT_MARGIN );
    42. QPoint bottomRightT( QMAX(mousePRESSPoint.x(), mouseRELEASEPoint.x()) + TEXT_MARGIN ,
    43. QMAX(mousePRESSPoint.y(), mouseRELEASEPoint.y()) + TEXT_MARGIN );
    44. QRect selectionTEXT( topLeftT, bottomRightT );
    45. /* display rect mesure text crop !!! */
    46.  
    47. QPen pen;
    48. pen.setStyle( Qt::SolidLine );
    49. pen.setCapStyle( Qt::RoundCap );
    50. pen.setColor( fillrectcolor );
    51. pen.setWidth( 2 );
    52. /* display rect to crop image !!! */
    53. painter.setPen( pen);
    54. painter.drawRect(selectionIMAGE);
    55. /* display rect to crop image !!! */
    56. /* display text image ratio text on crop image !!! */
    57. pen.setColor( textColor );
    58. painter.setPen( pen);
    59. /* display text image ratio text on crop image !!! */
    60. painter.drawText(selectionTEXT,selectionText);
    61. //////// Show_Actual_Params(); /* debug display coordinate all */
    62. }
    63.  
    64. void Image_Operator::mousePressEvent(QMouseEvent *e)
    65. {
    66. qDebug() << "### mousePressEvent -> " << e->x() << "x" << e->y();
    67. mousePRESSPoint = e->pos();
    68. }
    69. void Image_Operator::mouseReleaseEvent(QMouseEvent *e)
    70. {
    71. qDebug() << "### mouseReleaseEvent -> " << e->x() << "x" << e->y();
    72. mouseRELEASEPoint = e->pos();
    73. }
    74.  
    75. void Image_Operator::mouseMoveEvent(QMouseEvent *e)
    76. {
    77. qDebug() << "### mouseReleaseEvent -> " << e->x() << "x" << e->y();
    78. mouseMOVEPoint = e->pos();
    79. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by patrik08; 16th March 2007 at 14:56.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.