Results 1 to 2 of 2

Thread: trouble when moving dynamically created custom Widgets

  1. #1
    Join Date
    Sep 2013
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default trouble when moving dynamically created custom Widgets

    In my project I give the user a button that allows him to dynamically drop-add textfields on an area. Each textfield can be moved around via a drag started with a moveButton, also contains a minimizeButton. My solution works fine if there is one textfield. Both buttons work. If there are multiple textfields, each time I move one, the others disappear and it also causes the minimizeButton`s redraw to be drawn on top of the textfield without deleting the old drawing.

    the textfield is called WholeField: inherits from QWidget, contains QTextEdit and a moveButton(custom,inherits QAbstractButton) to move the WholeField around via drag and a minmizeButton that hides the QTextEdit and causes a redraw to happen

    the area: called IdeaPlane: inherits QWidget, serves as a background, accepts drops
    Qt Code:
    1. void IdeaPlane::dropEvent(QDropEvent *event)
    2. {
    3. if (event->mimeData()->hasFormat("moveWholeField"))
    4. {
    5. qDebug("dropEvent-moveWholeField entered");
    6. event->setDropAction(Qt::MoveAction);
    7. event->accept();
    8. //variable to store the drop`s position
    9. dropPos = event->pos(); //dropPos is QPoint, a public member of IdeaPlane
    10. emit drag_move_done();
    11.  
    12. }
    13. else
    14. {
    15. event->ignore();
    16. }
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 

    the signal drag_move_done() is connected to a slot in WholeField`s constructor:
    Qt Code:
    1. WholeField::WholeField(QWidget *parent) :
    2. QWidget(parent),minimized(false)
    3. {
    4. .....
    5. IdeaFieldButton *minimizeButton = new IdeaFieldButton(this,IdeaFieldButton::minimizeButton);
    6. IdeaFieldButton *moveButton = new IdeaFieldButton(this,IdeaFieldButton::moveButton);
    7. connect(this->parentWidget(),SIGNAL(drag_move_done()),this,SLOT(drag_move() ) );
    8. .....
    9. }
    To copy to clipboard, switch view to plain text mode 

    that slot finds the pointer to the IdeaPlane via a call to parentWidget, casts it to the IdeaPlane type and then accesses the drop position to move the corresponding WholeField accordingly.
    void WholeField::drag_move()
    Qt Code:
    1. {
    2. IdeaPlane *plane = qobject_cast<IdeaPlane *>(this->parentWidget() );
    3. this->move(plane->dropPos);
    4. }
    To copy to clipboard, switch view to plain text mode 

    Why would this not work with multiple WholeFields added but work with one? How do I fix this?
    I have been stuck with this for a day...

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: trouble when moving dynamically created custom Widgets

    read my sig.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. use value from dynamically created widget in a slot
    By Cyrebo in forum Qt Programming
    Replies: 55
    Last Post: 23rd April 2013, 15:51
  2. Replies: 3
    Last Post: 11th August 2011, 18:16
  3. Dynamically created buttons.
    By Tomasz in forum Newbie
    Replies: 26
    Last Post: 2nd December 2010, 10:40
  4. Replies: 0
    Last Post: 13th October 2010, 21:28
  5. Trouble while viewing a created a toolbar!!
    By aditya.kaole in forum Qt Programming
    Replies: 1
    Last Post: 6th April 2009, 22:04

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.