Results 1 to 18 of 18

Thread: How to find out the type of the clicked item..

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to find out the type of the clicked item..

    still gives error and this is what it says..

    [HTML]

    error: no match for 'operator==' in '(((QList<Q3CanvasItem*>*)
    ((ImageDraw*)this)) + 56u)->QList<T>::at [with T = Q3CanvasItem*](i) == Q3ValueL
    ist<T>::at(typename QLinkedList<T>::size_type) [with T = Q3CanvasItem*](i)'

    [/HTML]

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to find out the type of the clicked item..

    Can you paste your code ?

  3. #3
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to find out the type of the clicked item..

    Yaa..

    Here is the code:

    CanvasMouse.cpp This file handles the mouse click events and then finds the point through the collision method and sends the info to the ImageDraw class..
    Qt Code:
    1. #include "canvasmouse.h"
    2. CanvasMouse::CanvasMouse(Q3Canvas *pCanvas, QFrame *frame): Q3CanvasView(frame)
    3. {
    4. m_pCanvas = pCanvas;
    5. Q3CanvasView::setCanvas(m_pCanvas);
    6. m_pCanvas->setBackgroundColor(Qt::white);
    7. m_pCanvas->resize(400, 400);
    8. imgdraw = new ImageDraw(m_pCanvas);
    9. setDraw = false;
    10. startDraw = false;
    11.  
    12. }
    13.  
    14. CanvasMouse::~CanvasMouse()
    15. {
    16. }
    17.  
    18. void CanvasMouse::contentsMousePressEvent(QMouseEvent* e)
    19. {
    20. if(setDraw)
    21. {
    22. if(e->button() == Qt::LeftButton)
    23. {
    24. pPress = inverseWorldMatrix().map(e->pos());
    25. startDraw = true;
    26. }
    27. }
    28.  
    29. }
    30. void CanvasMouse::contentsMouseReleaseEvent(QMouseEvent* e)
    31. {
    32.  
    33. if(setDraw)
    34. {
    35. if((e->button() == Qt::LeftButton) && startDraw)
    36. {
    37. pRelease = inverseWorldMatrix().map(e->pos());
    38. Q3CanvasItemList l = m_pCanvas->collisions(pRelease);;
    39.  
    40. imgdraw->selectLine(l);
    41. }
    42. }
    43. }
    To copy to clipboard, switch view to plain text mode 

    [B]ImageDraw.cpp [B]: This class does the finding of the line number and rect number. Its the selectLine function that finds the line number.

    Qt Code:
    1. #include "imagedraw.h"
    2. #include <Q3ValueList>
    3.  
    4. ImageDraw::ImageDraw(Q3Canvas *pCanvas): m_pCanvas(pCanvas)
    5. {
    6. drawLine();
    7. drawRectangle();
    8. }
    9. ImageDraw::~ImageDraw()
    10. {
    11. }
    12. void ImageDraw::drawLine()
    13. {
    14. int i;
    15. int xxPoint = 2,xyPoint = 2,yxPoint = 202,yyPoint = 2;
    16. lineNum = 20;
    17. m_pCanvasLine = new Q3CanvasLine*[lineNum];
    18. for(i=0;i<lineNum;i++)
    19. {
    20. xyPoint = (i+1)*4;
    21. yyPoint = xyPoint;
    22. m_pCanvasLine[i] = new Q3CanvasLine(m_pCanvas);
    23. m_pCanvasLine[i]->setPoints(xxPoint,xyPoint,yxPoint,yyPoint);
    24. m_pCanvasLine[i]->show();
    25.  
    26. }
    27.  
    28. m_pLineItem = new Q3CanvasLine(m_pCanvas);
    29. lineList.append(m_pLineItem);
    30.  
    31. }
    32.  
    33. void ImageDraw::drawRectangle()
    34. {
    35. int xPoint = 4, yPoint = 100;
    36. int height = 50, width = 80;
    37. int i;
    38. recNum = 5;
    39. m_pCanvasRectangle = new Q3CanvasRectangle*[recNum];
    40. for(i=0;i<recNum;i++)
    41. {
    42. m_pCanvasRectangle[i] = new Q3CanvasRectangle(xPoint, yPoint, width, height, m_pCanvas);
    43. m_pCanvasRectangle[i]->show();
    44. yPoint += 75;
    45. }
    46.  
    47. }
    48.  
    49. void ImageDraw::selectLine(Q3CanvasItemList item)
    50. {
    51. int i=0;
    52. m_itemLine = item;
    53. for (Q3CanvasItemList::Iterator it= m_itemLine.begin(); it!= m_itemLine.end(); ++it)
    54. {
    55. if ( (*it)->rtti() == 7 )
    56. {
    57. for(i=0;i<lineList.size();i++)
    58. {
    59. if(lineList.at(i) == m_itemLine.at(i))
    60. {
    61.  
    62. QMessageBox::information(this, tr("Mouse Event"),tr("Line %1 Mouse Event Handled ").arg(i));
    63.  
    64. }
    65.  
    66. }
    67. }
    68. else if ( (*it)->rtti() == 5 )
    69. {
    70. QMessageBox::information(this, tr("Mouse Event"),tr("Rectangle Mouse Event Handled "));
    71. }
    72. }
    73. }
    To copy to clipboard, switch view to plain text mode 

    ImageDraw.h: The header file where i have made the dec.
    Qt Code:
    1. #ifndef IMAGEDRAW_H
    2. #define IMAGEDRAW_H
    3.  
    4. #include <QtGui>
    5. #include <Q3Canvas>
    6. #include <qdir.h>
    7. #include <QColor>
    8. #include <Q3CanvasLine>
    9. #include <qevent.h>
    10. #include <QPoint>
    11. #include <Q3CanvasView>
    12. #include <Q3ScrollView>
    13. #include <Q3CanvasItem>
    14. #include <Q3CanvasItemList>
    15. #include <QPen>
    16. #include <QList>
    17.  
    18. class ImageDraw : public Q3CanvasView
    19. {
    20. public:
    21. ImageDraw(Q3Canvas *pCanvas);
    22. ~ImageDraw();
    23. void drawLine();
    24. void drawRectangle();
    25. void selectLine(Q3CanvasItemList item);
    26. //void selectRect(Q3CanvasItemList item);
    27.  
    28. private:
    29. Q3Canvas *m_pCanvas;
    30. Q3CanvasLine **m_pCanvasLine;
    31. Q3CanvasRectangle **m_pCanvasRectangle;
    32. Q3CanvasItemList m_itemLine;
    33. Q3CanvasItemList m_itemRect;
    34. QList<Q3CanvasItem *> lineList;
    35. Q3CanvasItem *m_pLineItem;
    36. //const QPoint m_pointLine,m_pointRect;
    37. int lineNum;
    38. int recNum;
    39. bool lineDraw,rectDraw;
    40. };
    41.  
    42. #endif
    To copy to clipboard, switch view to plain text mode 

    Please tell me what can be the problem...

  4. #4
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to find out the type of the clicked item..

    Hi munna...

    Thanks a lot for ur suggestions..

    I used the function collidesWith(lineList.at(i)) and it gave me the value of the line i have clicked on...

    Also i was able to create the lineList ..

    One doubt... How can I colour the created line with some other colour..

    Using the pen, we create a line with another coloue but is there any function like stColour for the line which could set the lines colour to the one i need..

    Thanking you,
    Kapil

  5. #5
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to find out the type of the clicked item..

    Please Explain the following lines.

    Qt Code:
    1. m_pCanvasLine = new Q3CanvasLine*[lineNum];
    2. for(i=0;i<lineNum;i++) {
    3. xyPoint = (i+1)*4;
    4. yyPoint = xyPoint;
    5. m_pCanvasLine[i] = new Q3CanvasLine(m_pCanvas);
    6. m_pCanvasLine[i]->setPoints(xxPoint,xyPoint,yxPoint,yyPoint);
    7. m_pCanvasLine[i]->show();
    8. }
    9. m_pLineItem = new Q3CanvasLine(m_pCanvas);
    10. lineList.append(m_pLineItem);
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. m_pCanvasRectangle = new Q3CanvasRectangle*[recNum];
    2. for(i=0;i<recNum;i++){
    3. m_pCanvasRectangle[i] = new Q3CanvasRectangle(xPoint, yPoint, width, height, _pCanvas);
    4. m_pCanvasRectangle[i]->show();
    5. yPoint += 75;
    6. }
    To copy to clipboard, switch view to plain text mode 

    As i said earlier you dont need to maintain two lists. One list should be more than enough to achieve your task. Please try to find out what exactly you need to achieve and what you are doing in your code.

  6. The following user says thank you to munna for this useful post:

    Kapil (31st March 2006)

  7. #6
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to find out the type of the clicked item..

    Quote Originally Posted by munna
    Please Explain the following lines.

    Qt Code:
    1. m_pCanvasLine = new Q3CanvasLine*[lineNum];
    2. for(i=0;i<lineNum;i++) {
    3. xyPoint = (i+1)*4;
    4. yyPoint = xyPoint;
    5. m_pCanvasLine[i] = new Q3CanvasLine(m_pCanvas);
    6. m_pCanvasLine[i]->setPoints(xxPoint,xyPoint,yxPoint,yyPoint);
    7. m_pCanvasLine[i]->show();
    8. }
    9. m_pLineItem = new Q3CanvasLine(m_pCanvas);
    10. lineList.append(m_pLineItem);
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. m_pCanvasRectangle = new Q3CanvasRectangle*[recNum];
    2. for(i=0;i<recNum;i++){
    3. m_pCanvasRectangle[i] = new Q3CanvasRectangle(xPoint, yPoint, width, height, _pCanvas);
    4. m_pCanvasRectangle[i]->show();
    5. yPoint += 75;
    6. }
    To copy to clipboard, switch view to plain text mode 

    As i said earlier you dont need to maintain two lists. One list should be more than enough to achieve your task. Please try to find out what exactly you need to achieve and what you are doing in your code.

    Hi.. yaa i understood it.. i was doing this mistake.. i after that removed the array and just maintained the QList as you had told me too.. also i was able to view the line number as i told in the reply just above ur last reply...

    Thanks a lot for ur help..

    Please tell me that is there any setColour sort of function for chaging the line or rectangle colour on click.. or i have to set a pen and recreate the line or rect over the created line...

    Thanks again...

    Kapil

Similar Threads

  1. Compile 4.4.0
    By LordQt in forum Installation and Deployment
    Replies: 18
    Last Post: 29th May 2008, 13:43
  2. problems installing Qt opensource with msvc2008 support
    By odin1985 in forum Installation and Deployment
    Replies: 6
    Last Post: 24th May 2008, 09:06
  3. How to know wich item is clicked QTreeWidget
    By ^NyAw^ in forum Qt Programming
    Replies: 13
    Last Post: 6th November 2007, 23:47
  4. dummy question(Error)
    By Masih in forum Qt Programming
    Replies: 12
    Last Post: 19th July 2007, 23:38
  5. Getting item from QTableView when clicked on
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 11:58

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.