Results 1 to 3 of 3

Thread: QGraphicsRectItem selected line

  1. #1
    Join Date
    Jul 2009
    Location
    Dundee, United Kingdom
    Posts
    18
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QGraphicsRectItem selected line

    Hello,
    It's my first post here, so sorry if I'm starting a thread which already has been answered. I googled for the answer, but found nothing useful...

    Anyway - I'm working on a project with a QGraphicsView-Scene-RectItem class implementation. The main functions available to the user should be the dragging (already done), selecting (done in 50%), resizing (problem here) and deleting rectangles (QGraphicsRectItems).

    The problem I have now is with the ItemIsSelectable flag. I set it in the constructor of MyRectangle class, which inherits from QGraphicsRectItem. This allows for selecting the item, but I would really need to change the line style when the item gets selected (now it's barely noticeable). How can this be achieved? Should I reimplement the mousePressEvent? If so - how to deselect all other items on the scene besides the one under the mouse...

    I will really appreciate any help,
    Sending regards,

    Bill

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QGraphicsRectItem selected line

    Quote Originally Posted by Bill View Post
    Hello,
    It's my first post here, so sorry if I'm starting a thread which already has been answered. I googled for the answer, but found nothing useful...
    Next time also use the board search function

    Two possibilities:
    • Create your own QStyle
    • reimp the paint function with

    Qt Code:
    1. if (option & QStyle::State_HasFocus)
    2. {
    3. // draw a custom selection rect
    4. }
    5.  
    6. // remove the selection flag and call the base implementation
    7. QStyleOptionGraphicsItem *o = const_cast<QStyleOptionGraphicsItem*> (option);
    8. o->state &= ~QStyle::State_HasFocus;
    9. QGraphicsRectItem::paint(painter, o, widget);
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Lykurg for this useful post:

    Bill (17th July 2009)

  4. #3
    Join Date
    Jul 2009
    Location
    Dundee, United Kingdom
    Posts
    18
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsRectItem selected line

    Hi,
    Thank you for the rapid reply :-). The reimplementation of paint() works like a charm. I saw it in the Diagram application from "C++ GUI programming with Qt" (chapter 8), but didn't have a clue that I should use it. Thanks.

    By the way - what would be your general suggestion to implementing resize handles on the rectangles (at least in one corner)? I found a couple of threads on Qt Centre concerning this topic...

    Regards,
    Bill

Similar Threads

  1. Why is my application's CPU usage always > 50%
    By richardander in forum Qt Programming
    Replies: 10
    Last Post: 14th October 2010, 22:22
  2. QTcpSocket exception.
    By Fastman in forum Qt Programming
    Replies: 9
    Last Post: 29th January 2008, 13:51
  3. Qwizard crashed when created in a slot
    By joshlareau in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2008, 09:16
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42

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.