Results 1 to 2 of 2

Thread: About QGraphicsItem question

  1. #1
    Join Date
    Mar 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Post About QGraphicsItem question

    when QGraphicsItem selected in QGraphicsScene, its bound will show in dashline.
    How can i change this property?
    i don't want to show dashline when QGraphicsItem selected.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: About QGraphicsItem question

    I think you'll need to create a subclass and reimplement virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) to draw the selection yourself. In order to prevent rendering of the default selection rect, you'll need to clear the QStyle::State_Selected flag from option argument:
    Qt Code:
    1. // header, QGraphicsItemBaseClass should be the one you want to subclass (QGraphicsPixmapItem,QGraphicsEllipseItem,...)
    2.  
    3. class MyGraphicsItem:public QGraphicsItemBaseClass{
    4. public:
    5. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    6. //...
    7.  
    8. // .cpp
    9. void MyGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    10. QStyleOptionGraphicsItem opt = *option;
    11. opt.state &= ~QStyle::State_Selected; // clears the default selection marker
    12. QGraphicsItemBaseClass::paint(painter,&opt,widget); // render graphics item without selection rect
    13. //...
    14. }
    To copy to clipboard, switch view to plain text mode 
    You can test for the QStyle::State_Selected flag in paint method to render the selection your way:
    Qt Code:
    1. void MyGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    2. if( option->state & QStyle::State_Selected ){
    3. //... your selection rendering method here
    4. }
    5. }
    To copy to clipboard, switch view to plain text mode 

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

    stevel (26th October 2011)

Similar Threads

  1. QGraphicsItem .. Scene .. View question?
    By DirtyBrush in forum Qt Programming
    Replies: 21
    Last Post: 19th October 2010, 09:12
  2. Replies: 4
    Last Post: 13th July 2010, 21:04
  3. QGraphicsItem pos() method question!
    By zgulser in forum Qt Programming
    Replies: 0
    Last Post: 20th August 2009, 19:56
  4. Simple QGraphicsItem question
    By godmodder in forum Qt Programming
    Replies: 2
    Last Post: 13th November 2008, 17:34
  5. QGraphicsItem move question
    By mhoover in forum Qt Programming
    Replies: 2
    Last Post: 7th December 2006, 19:01

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.