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
// MYSlot.h
public:
int GVar;
public slots:
void Slider_ValueChanged();
private:
Ui_MyForm ui;
// MYSlot.h
public:
int GVar;
QGraphicsScene scene;
QGraphicsView * view;
public slots:
void Slider_ValueChanged();
private:
Ui_MyForm ui;
To copy to clipboard, switch view to plain text mode
--------------------------------------------
// MySlot.cpp
// The Constructor
{
Ui_MyForm d;
MySlot::GVar=1;
//scene = new QGraphicsScene;
ui.setupUi(this);
}
// MySlot.cpp
// The Constructor
MySlot::MySlot(QWidget *parent)
: QWidget(parent)
{
Ui_MyForm d;
MySlot::GVar=1;
//scene = new QGraphicsScene;
view = new QGraphicsView(&(MySlot::scene));
ui.setupUi(this);
}
To copy to clipboard, switch view to plain text mode
----------------------------------------
Slider Value Changed Slot.
void MySlot::Slider_ValueChanged()
{
GVar= (int)(ui.horizontalSlider->value());
MySlot::scene.addEllipse (10, 10, GVar, 10,
QPen(Qt
::black,
15, Qt
::SolidLine, Qt
::RoundCap,
Qt::MiterJoin),
QBrush(Qt
::blue, Qt
::DiagCrossPattern));
MySlot::scene.setBackgroundBrush(Qt::red);
MySlot::view->setAttribute(Qt::WA_DeleteOnClose);
CustomSlot::view ->show();
}
void MySlot::Slider_ValueChanged()
{
GVar= (int)(ui.horizontalSlider->value());
MySlot::scene.addEllipse (10, 10, GVar, 10,
QPen(Qt::black, 15, Qt::SolidLine, Qt::RoundCap,
Qt::MiterJoin),
QBrush(Qt::blue, Qt::DiagCrossPattern));
MySlot::scene.setBackgroundBrush(Qt::red);
MySlot::view->setAttribute(Qt::WA_DeleteOnClose);
CustomSlot::view ->show();
}
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
Bookmarks