Results 1 to 4 of 4

Thread: QGraphicsView Problem !!

  1. #1
    Join Date
    Jun 2008
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsView Problem !!

    i'm making a project, one of its parts in to control the size and place of any shape using sliders.

    what i have got till now is, The shape's size is increasing when the slider's value increases,
    the Problem is when decreasing the value of the slider, Nothing happen to the shape.

    here is wt i did

    Qt Code:
    1. // MYSlot.h
    2. public:
    3. int GVar;
    4. QGraphicsView * view;
    5.  
    6. public slots:
    7. void Slider_ValueChanged();
    8.  
    9. private:
    10. Ui_MyForm ui;
    To copy to clipboard, switch view to plain text mode 
    --------------------------------------------

    Qt Code:
    1. // MySlot.cpp
    2.  
    3. // The Constructor
    4.  
    5. MySlot::MySlot(QWidget *parent)
    6. : QWidget(parent)
    7. {
    8. Ui_MyForm d;
    9. MySlot::GVar=1;
    10. //scene = new QGraphicsScene;
    11. view = new QGraphicsView(&(MySlot::scene));
    12. ui.setupUi(this);
    13. }
    To copy to clipboard, switch view to plain text mode 
    ----------------------------------------

    Slider Value Changed Slot.

    Qt Code:
    1. void MySlot::Slider_ValueChanged()
    2. {
    3. GVar= (int)(ui.horizontalSlider->value());
    4. MySlot::scene.addEllipse (10, 10, GVar, 10,
    5. QPen(Qt::black, 15, Qt::SolidLine, Qt::RoundCap,
    6. Qt::MiterJoin),
    7. QBrush(Qt::blue, Qt::DiagCrossPattern));
    8.  
    9. MySlot::scene.setBackgroundBrush(Qt::red);
    10. MySlot::view->setAttribute(Qt::WA_DeleteOnClose);
    11. CustomSlot::view ->show();
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 

    Again, The Problem is .. When the slider's value increases, the shape's size increases, when the slider's value decreases, Nothing happen to the shape.

    Thanks

  2. #2
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsView Problem !!

    Each time your slot is called, you're creating a new ellipse. Instead, you will want to change the size of an existing item, then call update() to repaint it.

  3. #3
    Join Date
    Jun 2008
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView Problem !!

    Actually i used update function, but nothing happened !!

    here is the Slot with updated function.

    Qt Code:
    1. GVar= (int)(ui.horizontalSlider->value());
    2.  
    3. MySlot::scene.addEllipse (10, 10, GVar, GVar,
    4. QPen(Qt::black, 15, Qt::SolidLine, Qt::RoundCap,
    5. Qt::MiterJoin),
    6. QBrush(Qt::blue, Qt::DiagCrossPattern));
    7.  
    8. MySlot::scene.setBackgroundBrush(Qt::red);
    9.  
    10. MySlot::view->update();
    11.  
    12. MySlot::view->setAttribute(Qt::WA_DeleteOnClose);
    13. MySlot::view ->show();
    14. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Gamalof; 13th June 2008 at 19:08.

  4. #4
    Join Date
    Jun 2008
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView Problem !!

    I Got My incredible error :| , i was drawing circle"s" is the QSlider's value changed slot.

    which gave me this bad result - many objects in the memory plus something like shadow appears - i solved it simply by drawing only one circle by this check :-

    Qt Code:
    1. if (MySlot::MyE == NULL)
    2. {
    3. MySlot::MyE = MySlot::scene.addEllipse (10, 10, 10, 10,
    4. QPen(Qt::red),
    5. QBrush(Qt::white));
    6. MySlot::scene.setBackgroundBrush(Qt::red);
    7. }
    To copy to clipboard, switch view to plain text mode 

    then added the code which controls the size and location of the circle

    Qt Code:
    1. MySlot::MyE->setRect(GVar3, GVar2, GVar, GVar );
    2. MySlot::view->setAttribute(Qt::WA_DeleteOnClose);
    3. MySlot::view ->show();
    4. MySlot::view->update();
    To copy to clipboard, switch view to plain text mode 

    Thanks

Similar Threads

  1. Mystic Problem (QGraphicsView + QGLWidget)
    By NoRulez in forum Qt Programming
    Replies: 2
    Last Post: 28th April 2008, 10:39
  2. problem in rendering opengl on QGraphicsView
    By Sandip in forum Qt Programming
    Replies: 17
    Last Post: 15th April 2008, 08:27
  3. Problem determining size of QGraphicsView
    By Bocki in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2008, 14:54
  4. QGraphicsView scrolling problem with 4.3.0
    By hb in forum Qt Programming
    Replies: 8
    Last Post: 30th August 2007, 22:18
  5. Problem with QGraphicsView.
    By kiranraj in forum Qt Programming
    Replies: 1
    Last Post: 4th July 2007, 19:44

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.