Results 1 to 4 of 4

Thread: QGraphicsItem Resize Problem

  1. #1
    Join Date
    Dec 2008
    Posts
    52
    Thanks
    3
    Qt products
    Qt4

    Default QGraphicsItem Resize Problem

    Hi,
    I am using the DiagramScene example of Qt example for my application, where we have a mainwindow with tool box and QGraphicsView, in toolbox we have some shapes which r drawn using a DiagramItem class which inherits QGraphicsPolygonItem.
    My problem is I want to give the Item the resize functionality where if the user click on item the user must be given the 6points on the rectangle to drag and resize the Item.

    Where should i implement this functionality in DiagramScene class or DiagramItem class. in DiagramItem Class there is no paint() to repaint the Item.
    What are the methods to implement.
    could any one help to achieve this functionality.
    thank u in advance.

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem Resize Problem

    the paint functionality is there for graphicsitem ...
    reimplement

    QGraphicsItem:aint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget

    http://doc.trolltech.com/4.5/qgraphicsitem.html#paint

    and update() also available ..

  3. #3
    Join Date
    Dec 2008
    Posts
    52
    Thanks
    3
    Qt products
    Qt4

    Default Re: QGraphicsItem Resize Problem

    I am New to Qt plz help me with some more Ideas

  4. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem Resize Problem

    widgets paint itself using this protected function
    QWidget:aintEvent();

    so if u want to change the actual structure of the widget or with the widget u want to create new widget with different size and structure we need to reimplement the void paintEvent() virtual function ... u can see lots of Qt examples using this ...

    http://doc.trolltech.com/4.5/qpaintevent.html

    paintEvent() occurs:
    paintEvent() method is automatically called when:
    * your widget is shown for first time .
    * after a window has been moved to reveal some part (or all ) the widget .
    * the window in which the widget lies is restored after being minimzed
    and more important ..
    when u call update()
    update():
    it will remove the currently available paint and start painting with the paintEvent() function ..
    places a paintevent into the event queue, no painting occurs untill current metod exits, and control returns to event handler ,,
    paintEvent() <- QWidget ,,, like wise
    paint( Painter *painter, const QStyleOptionGraphicsItem *, QWidget * ) <- QGraphicsItem


    if we need to re draw the item , set color , add line, text, rectangle inside the item reimplement these two functions ..
    Qt Code:
    1. void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *);
    2. QRectF boundingRect() const;
    To copy to clipboard, switch view to plain text mode 

    in your case .. if the user clicks the item .. in item class set some flag and call update() to repaint .. update() will call your QGraphicsItem:aint() .. inside with the set flag redraw your six points ...

Similar Threads

  1. Very strange socket programming problem
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2008, 12:05
  2. Qt 4.4 QDockWidget resize problem
    By MarkSutton in forum Qt Tools
    Replies: 2
    Last Post: 27th September 2008, 08:55
  3. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 12:48
  4. Replies: 1
    Last Post: 10th August 2008, 18:55
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.