Results 1 to 3 of 3

Thread: how can i mark points on top of a Image?

  1. #1
    Join Date
    Apr 2010
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default how can i mark points on top of a Image?

    I am trying to mark points on top of a image,
    - I select the topleft and bottomright points on the image
    - generate grid points on top of the image (something like this )
    http://img169.imageshack.us/img169/9...otfigure11.jpg
    - the grid should be cleared later

    currently i created a ImageItem class derived from QpixmapItem
    Qt Code:
    1. #ifndef IMAGEITEM_H
    2. #define IMAGEITEM_H
    3.  
    4. #include <QGraphicsPixmapItem>
    5. #include <QtDebug>
    6. #include <QGraphicsSceneMouseEvent>
    7. #include <QPoint>
    8. #include <QPainter>
    9. #include <QObject>
    10.  
    11. class ImageItem : public QObject ,public QGraphicsPixmapItem
    12. {
    13. Q_OBJECT
    14. public:
    15. ImageItem();
    16. ImageItem(QGraphicsItem *, QGraphicsScene*);
    17. public slots:
    18. void mousePressEvent(QGraphicsSceneMouseEvent *event);
    19. signals:
    20. void mouseClicked(QPointF);
    21.  
    22. };
    23.  
    24. #endif // IMAGEITEM_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include "imageitem.h"
    2.  
    3. ImageItem::ImageItem()
    4. {
    5. }
    6.  
    7. ImageItem::ImageItem(QGraphicsItem *parent, QGraphicsScene* scene) : QGraphicsPixmapItem(parent,scene){
    8.  
    9. }
    10.  
    11. void ImageItem::mousePressEvent(QGraphicsSceneMouseEvent *event){
    12. emit mouseClicked(event->pos());
    13. }
    To copy to clipboard, switch view to plain text mode 

    i can get the topleft and bottomright points from the mousePressEvent
    Now my problem is how can i draw points (which can be removed later) on top of QPixmapItem??

    any ideas how to implement this? or if u have a sample code please share

  2. #2
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    287
    Thanks
    23
    Thanked 31 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: how can i mark points on top of a Image?

    That link looks like a form or dialog with a image. What about a label to display a image and QPainter to draw the points on top ?
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

  3. #3
    Join Date
    Apr 2010
    Posts
    22
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: how can i mark points on top of a Image?

    Quote Originally Posted by montamer View Post
    any ideas how to implement this? or if u have a sample code please share
    This is my code to emulate what happen when a user click a mouse button on a desktop and then moves the mouse. A dashed retangle is drawn on desktop to let user see "selection area". All this is done on a screenshoot image. There are
    mainly 3 methods:

    mousePressEvent =>get mouse coords, start coords
    mouseMoveEvent =>get end coords and draw a rectangle on image,
    mouseReleaseEvent =>restore original image

    I hope you can use my code to do whatever you need.
    Bye
    Alberto

    Qt Code:
    1. .h:
    2. int startx,starty,endx,endy,addable,printed;
    3. QPixmap originalPixmap;//image where i draw
    4. QPixmap copyPixmap;//temporary image
    5. QPixmap savePixmap;//original image
    6. QPen pen;
    7.  
    8.  
    9. .cpp:
    10. void Widget::mousePressEvent(QMouseEvent *event)
    11. {
    12. startx=event->globalPos().x()-offsetx+ui->scrollArea->horizontalScrollBar()->value();
    13. starty=event->globalPos().y()-offsety+ui->scrollArea->verticalScrollBar()->value();
    14. addable=1;
    15. QObject::disconnect(ui->lineEdit,SIGNAL(textChanged(QString)),this,SLOT(checkText(QString)));
    16. }
    17.  
    18. void Widget::mouseMoveEvent(QMouseEvent *event)
    19. {
    20. if(addable==1){
    21. if(printed==1){
    22. originalPixmap=copyPixmap.copy(QRect());
    23. ui->label->setPixmap(originalPixmap);
    24. }
    25. QPainter painter(&originalPixmap);
    26.  
    27. painter.setPen(QPen(Qt::gray, 1, Qt::DashLine, Qt::RoundCap, Qt::RoundJoin));
    28. painter.drawRect(startx,
    29. starty,
    30. event->globalPos().x()-startx-offsetx+ui->scrollArea->horizontalScrollBar()->value(),
    31. event->globalPos().y()-starty-offsety+ui->scrollArea->verticalScrollBar()->value() );
    32. painter.end();
    33. ui->label->setPixmap(originalPixmap);
    34. printed=1;
    35. }
    36. }
    37.  
    38. void Widget::mouseReleaseEvent(QMouseEvent *event)
    39. {
    40. printed=0;
    41. originalPixmap=copyPixmap.copy(QRect());
    42. ui->label->setPixmap(originalPixmap);
    43. if(addable==1){
    44. endx=event->globalPos().x()-offsetx+ui->scrollArea->horizontalScrollBar()->value();
    45. endy=event->globalPos().y()-offsety+ui->scrollArea->verticalScrollBar()->value();
    46. addable=2;
    47. connect(ui->lineEdit,SIGNAL(textChanged(QString)),this,SLOT(checkText(QString)));
    48. }
    49. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 6
    Last Post: 21st September 2009, 10:55
  2. Replies: 2
    Last Post: 10th June 2009, 23:14
  3. Replies: 2
    Last Post: 21st October 2008, 20:20
  4. QTextEdit and mark Text
    By J-jayz-Z in forum Qt Programming
    Replies: 12
    Last Post: 28th September 2007, 00:14
  5. How to set visible the QTreeWidgetItem expand '+' mark
    By mcostalba in forum Qt Programming
    Replies: 3
    Last Post: 14th January 2007, 03:21

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.