Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to create a responsive/dynamic object?
Forum Updated to NodeBB v4.3 + New Features

How to create a responsive/dynamic object?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
12 Posts 3 Posters 2.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #3

    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.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    1
    • raven-worxR raven-worx

      @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?
      ...

      S Offline
      S Offline
      Sherlin N G
      wrote on last edited by
      #4

      @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.

      1 Reply Last reply
      0
      • raven-worxR raven-worx

        @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-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by raven-worx
        #5

        @Sherlin-N-G

        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);
        }
        

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        S 1 Reply Last reply
        0
        • raven-worxR raven-worx

          @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?
          ...

          S Offline
          S Offline
          Sherlin N G
          wrote on last edited by
          #6

          @raven-worx Its created using QTwidgets.

          1 Reply Last reply
          0
          • raven-worxR raven-worx

            @Sherlin-N-G

            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);
            }
            
            S Offline
            S Offline
            Sherlin N G
            wrote on last edited by
            #7

            @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-worxR 1 Reply Last reply
            0
            • S Sherlin N G

              @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-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #8

              @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

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              S 2 Replies Last reply
              0
              • raven-worxR raven-worx

                @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

                S Offline
                S Offline
                Sherlin N G
                wrote on last edited by
                #9

                @raven-worx Yes but the UI variable is private rite? Should I make it public? As I'm using it in the MyContainer class

                1 Reply Last reply
                0
                • raven-worxR raven-worx

                  @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

                  S Offline
                  S Offline
                  Sherlin N G
                  wrote on last edited by
                  #10

                  @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

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Sherlin N G
                    wrote on last edited by
                    #11

                    @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.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      Hi,

                      Did you check the documentation of installEventFilter ? It shows how it works with a practical example.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved