How to create a responsive/dynamic object?
-
I have created a Object which is movable and draggable which you can see in the snapshot.The problem is when I move the object in the ui corresponding x,y locations in line edits should get updated and similarly when I increase or decrease height/width corresponding values should get updated in line edits and vice versa.Please suggest I'm new to this tool.
-
I have created a Object which is movable and draggable which you can see in the snapshot.The problem is when I move the object in the ui corresponding x,y locations in line edits should get updated and similarly when I increase or decrease height/width corresponding values should get updated in line edits and vice versa.Please suggest I'm new to this tool.
@Sherlin-N-G said in How to create a responsive/dynamic object?:
I have created a Object which is movable and draggable which you can see in the snapshot
What type of 'Object'?
Is it created from C++ or QML?
Is your application a QML or QtWidgets application?
... -
Hi,
When you release the mouse you can grab the widget new geometry and update your line edits with these values.
As for the line edits, you should likely consider using QSpinBox and connect the
valueChanged
signal to a custom slot where you set your widget property accordingly. -
@Sherlin-N-G said in How to create a responsive/dynamic object?:
I have created a Object which is movable and draggable which you can see in the snapshot
What type of 'Object'?
Is it created from C++ or QML?
Is your application a QML or QtWidgets application?
...@raven-worx
Hi,Thanks for the reply
I created the object using the class in the below link
https://wiki.qt.io/Widget-moveable-and-resizeable.@SGaist
Hi,
A code snippet would be great.And QSpinBox doesnt take large values i believe.And if the line edit values are changed this should impact in the object and vice versa for this I dont think so signals/slots would work. -
@Sherlin-N-G said in How to create a responsive/dynamic object?:
I have created a Object which is movable and draggable which you can see in the snapshot
What type of 'Object'?
Is it created from C++ or QML?
Is your application a QML or QtWidgets application?
...mWidget->installEventFilter( container ); .... bool MyContainer::eventFilter( QObject* watched, QEvent* event ) { if( watched == mWidget ) { switch( event->type() ) { case QEvent::Resize: { QResizeEvent* re = static_cast<QResizeEvent*>( event ); heightEdit->setText( QString::number( re.size().height() ); widthEdit->setText( QString::number( re.size().width() ); } break; case QEvent::Move: { QMoveEvent* me = static_cast<QMoveEvent*>( event ); posXEdit->setText( QString::number(me->pos().x()) ); posYEdit->setText( QString::number(me->pos().y()) ); } break; } } return BaseClass:eventFilter(watched,event); }
-
@Sherlin-N-G said in How to create a responsive/dynamic object?:
I have created a Object which is movable and draggable which you can see in the snapshot
What type of 'Object'?
Is it created from C++ or QML?
Is your application a QML or QtWidgets application?
...@raven-worx Its created using QTwidgets.
-
mWidget->installEventFilter( container ); .... bool MyContainer::eventFilter( QObject* watched, QEvent* event ) { if( watched == mWidget ) { switch( event->type() ) { case QEvent::Resize: { QResizeEvent* re = static_cast<QResizeEvent*>( event ); heightEdit->setText( QString::number( re.size().height() ); widthEdit->setText( QString::number( re.size().width() ); } break; case QEvent::Move: { QMoveEvent* me = static_cast<QMoveEvent*>( event ); posXEdit->setText( QString::number(me->pos().x()) ); posYEdit->setText( QString::number(me->pos().y()) ); } break; } } return BaseClass:eventFilter(watched,event); }
@raven-worx
Thanks for the reply.I did not get what this statement does Can you please elaborate
mWidget->installEventFilter( container );and in the class MyContainer the below two lines are private members of mainwindow ui
heightEdit->setText( QString::number( re.size().height() );
widthEdit->setText( QString::number( re.size().width() );how can you use them in MyContainer class.
-
@raven-worx
Thanks for the reply.I did not get what this statement does Can you please elaborate
mWidget->installEventFilter( container );and in the class MyContainer the below two lines are private members of mainwindow ui
heightEdit->setText( QString::number( re.size().height() );
widthEdit->setText( QString::number( re.size().width() );how can you use them in MyContainer class.
@Sherlin-N-G said in How to create a responsive/dynamic object?:
Thanks for the reply.I did not get what this statement does Can you please elaborate
mWidget->installEventFilter( container );see this
@Sherlin-N-G said in How to create a responsive/dynamic object?:
and in the class MyContainer the below two lines are private members of mainwindow ui
you can access the widgets from your Designer UI via the
ui
variable. E.g.ui->nameOfTheElement
-
@Sherlin-N-G said in How to create a responsive/dynamic object?:
Thanks for the reply.I did not get what this statement does Can you please elaborate
mWidget->installEventFilter( container );see this
@Sherlin-N-G said in How to create a responsive/dynamic object?:
and in the class MyContainer the below two lines are private members of mainwindow ui
you can access the widgets from your Designer UI via the
ui
variable. E.g.ui->nameOfTheElement
@raven-worx Yes but the UI variable is private rite? Should I make it public? As I'm using it in the MyContainer class
-
@Sherlin-N-G said in How to create a responsive/dynamic object?:
Thanks for the reply.I did not get what this statement does Can you please elaborate
mWidget->installEventFilter( container );see this
@Sherlin-N-G said in How to create a responsive/dynamic object?:
and in the class MyContainer the below two lines are private members of mainwindow ui
you can access the widgets from your Designer UI via the
ui
variable. E.g.ui->nameOfTheElement
@raven-worx Hi,Thanks for the link.I'm getting an error here
monitoredObj->installEventFilter(filterObj);I did not get what monitored object means? and where should I add the above statement in the code,Is it in the constructor??Please suggest
-
@raven-worx
Hi
Sorry if I'm asking lame doubt.Please help me here I'm struck in the below line
mWidget->installEventFilter( container );what is mWidget(or the monitored widget as it says in the link which you sent)? and where should this statement be added ?Is it in the constructor?Please suggest.
-
Hi,
Did you check the documentation of installEventFilter ? It shows how it works with a practical example.