+ Reply to Thread
Results 1 to 3 of 3

Thread: QGraphicsView : change selected rectangle style

  1. #1
    Join Date
    Jul 2008
    Location
    East Coast, USA
    Posts
    40
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question QGraphicsView : change selected rectangle style

    Hi,

    I like that QGraphicsView has all the basic select machinery written in, so we can have rubber band select and click select in our apps.

    However, what I want to do is change the way the view indicates that the object is selected. By default it draws a dotted white rectangle along the bounding box. How can I change that?

    Thanks
    -K

  2. #2
    Join Date
    Jun 2008
    Posts
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView : change selected rectangle style

    you should look into Qt sources to find out the answer
    a dotted white rectangle along the bounding box is painted using internal Qt function, so you have to reimplement the paintEvent() and write there code for shape itself and for the selection box.

  3. #3
    Join Date
    Jul 2008
    Location
    East Coast, USA
    Posts
    40
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Thumbs up Re: QGraphicsView : change selected rectangle style

    Hi,

    I found the solution. You need to fiddle with the QStyleOptionGraphicsItem *option that is passed to the paint function.

    My custom widget subclasses QGraphicsPixmapItem. I had reimplemented the paint function to call the regular paint funct and then my custom stuff. What I do now is as follows

    Qt Code:
    1. void ThumbnailItem::paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
    2. QStyleOptionGraphicsItem myoption = (*option);
    3. myoption.state &= !QStyle::State_Selected;
    4. QGraphicsPixmapItem::paint(painter, &myoption, widget);
    5. .... my own drawing routines ....
    To copy to clipboard, switch view to plain text mode 

    So I trap option, unset the option.state QStyle::State_selected bit, and then pass it on. I then have my own code for indicating its selected.

    http://doc.trolltech.com/3.3/qstyle.html#details
    http://doc.trolltech.com/4.2/qstyleo...m-members.html


    -K
    Last edited by kghose; 28th July 2008 at 18:20. Reason: added refs

  4. The following user says thank you to kghose for this useful post:

    mattc (1st May 2012)

+ Reply to 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