[Interest] Fw: How to moving widgets inside the layout

Igor Mironchik igor.mironchik at gmail.com
Thu Sep 4 06:14:44 CEST 2014


Even you don’t need keep in mind spacing. Just check is you mouse position in QLayoutItem::geometry() and you will find the index in layout...

From: Igor Mironchik 
Sent: Thursday, September 04, 2014 7:08 AM
To: Jean Richard Lima 
Subject: Re: [Interest] How to moving widgets inside the layout

Hi,

you can iterate over the items in layout and calculate index of that item that you are moving now.

And with this index then you can make takeAt() and insertItem() at new position.

But when you will iterate over the items and calculate index don’t forget about spacing in layout.

From: Jean Richard Lima 
Sent: Thursday, September 04, 2014 1:40 AM
To: Igor Mironchik 
Subject: Re: [Interest] How to moving widgets inside the layout

Hi Igor, thanks for your atentantion! 

I thought about using the QLayoutItem, but I have no idea how. 
Can you give me a small example of how to do? 

Thank you very much. 

Hugs.

              Jean Richard Lima
        Consultor de Gestão e TIC
Software House de Projetos Específicos



2014-09-03 18:23 GMT-03:00 Igor Mironchik <igor.mironchik at gmail.com>:

  Hi,

  try QLayoutItem * QVBoxLayout::takeAt( int index ) and then void QVBoxLayout::insertItem( int index, QLayoutItem * item )

  ...

  From: Jean Richard Lima 
  Sent: Wednesday, September 03, 2014 11:38 PM
  To: interest at qt-project.org 
  Subject: [Interest] How to moving widgets inside the layout

  Hi people!

  I need moving widgets inside the layout must do exactly as is done in designer mode, move widgets within the layout and other widgets automatically realign, example:
  I have 4 widgets and want to get 3 and move the mouse to one above the 1st position, then he should be the first and realign the rest, I’m just not getting it.

  My mousePressEvent method is as follows:

  x =  ev->globalX();
  y =  ev->globalY();

  My mouseMoveEvent method is as follows:

      if(ev->buttons() & Qt::LeftButton)
      {
         move(ev->globalX()-this->x,ev->globalY()-this->y);
      }

  in my mouseReleaseEvent is:

  setGeometry(ev->globalX()-this->x, ev->globalY()-this->y, width(), height());


  The object is moving normally, but when released the mouse button, it stays where it is and nothing is redesigned and I need you to do exactly as the designer, when you move an object in a QVBoxLayout after releasing the mouse button everything is realigned automatically and the object being dragged into the new position. 

  Does anyone have any tips for me. 

  Thank you.

                Jean Richard Lima
          Consultor de Gestão e TIC
  Software House de Projetos Específicos

------------------------------------------------------------------------------
  _______________________________________________
  Interest mailing list
  Interest at qt-project.org
  http://lists.qt-project.org/mailman/listinfo/interest


  _______________________________________________
  Interest mailing list
  Interest at qt-project.org
  http://lists.qt-project.org/mailman/listinfo/interest


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140904/ab6f7541/attachment.html>


More information about the Interest mailing list