Results 1 to 5 of 5

Thread: QGraphicsLineItem how to make it easier to select/move the line?

  1. #1
    Join Date
    Mar 2012
    Posts
    14
    Thanks
    1
    Platforms
    Windows

    Default QGraphicsLineItem how to make it easier to select/move the line?

    I have sub classed QGraphicsLineItem, set flag movable and selectable, and draw them to a graphic scene..

    problem is the bounding rect is the line itself and it is hard to click/select/move them..

    what can i do to make the line easier to be selected?

    I've tried reimplementing the boundingRect() with QRectF(0,0,100,100) but yields no results..

    also increasing the pen width doesnt help either..

    thanks alot..
    Last edited by chaltier; 4th April 2012 at 07:01.

  2. #2
    Join Date
    Jan 2012
    Posts
    66
    Thanks
    20
    Thanked 2 Times in 2 Posts
    Platforms
    Windows

    Default Re: QGraphicsLineItem how to make it easier to select/move the line?

    I would reimplement shape() rather than boundingRect(). shape() is used to detect mouse clicks. The default implementation just calls boundingRect(), though. You could reimplement shape() as something like this:

    Qt Code:
    1. const int adjustment = 5;
    2. return path.addRect(boundingRect().adjusted(-adjustment, -adjustment, adjustment, adjustment);
    To copy to clipboard, switch view to plain text mode 

    Not tested, but I think it should work!

  3. #3
    Join Date
    Mar 2012
    Posts
    14
    Thanks
    1
    Platforms
    Windows

    Default Re: QGraphicsLineItem how to make it easier to select/move the line?

    Hi thanks for the reply..

    When my line is drawn vertically or horizontally, the adjustment does not make any differences..

    When my line is drawn diagonally, it creates a bounding rect with my line as the hypotenuse

    i only wan my line to be selected when i click on the line..

    thanks againn..

  4. #4
    Join Date
    Mar 2012
    Posts
    14
    Thanks
    1
    Platforms
    Windows

    Default Re: QGraphicsLineItem how to make it easier to select/move the line?

    Qt Code:
    1. QPainterPath myLine::shape() const
    2. {
    3. stroker.setWidth(30);
    4. path.moveTo(line().p1());
    5. path.lineTo(line().p2());
    6. return stroker.createStroke(path);
    7. }
    To copy to clipboard, switch view to plain text mode 

    this is what i did now..i was able to create an invisible handler for me to click it..

    anyone knows how do i set color to it so it wont be invisible?

    thanks

  5. #5
    Join Date
    Mar 2014
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsLineItem how to make it easier to select/move the line?

    @Chaltier - Even I m facing the same issue. I reimplemented the QGraphicsLineItem and created my own custom line item. The custom line item is hard to select, press and move. Currently I am using the boundingRect() and shape() methods of QGraphicsLineItem itself. I haven't implemented my own custom methods for these. What shoud I do to fix these issues?

Similar Threads

  1. How to make painting on mouse move?
    By athulms in forum Newbie
    Replies: 1
    Last Post: 3rd November 2011, 09:07
  2. How can I get a textCursor to move to a particular line?
    By aarelovich in forum Qt Programming
    Replies: 0
    Last Post: 22nd June 2010, 19:29
  3. How to select a line of text
    By benlyboy in forum Newbie
    Replies: 6
    Last Post: 25th April 2010, 23:56
  4. Window OS make distclean && qmake && make one line
    By patrik08 in forum General Programming
    Replies: 4
    Last Post: 22nd March 2007, 10:43
  5. how to move cursor to specific line in Text
    By showhand in forum Qt Programming
    Replies: 1
    Last Post: 24th August 2006, 09:55

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.