Results 1 to 7 of 7

Thread: Giving user facility to resize widgets run time

  1. #1
    Join Date
    Mar 2012
    Location
    India
    Posts
    102
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Giving user facility to resize widgets run time

    Hi,

    I have a an application where on one side I display a list of widgets and on the other side I have a QGraphicsView. When the application runs the user can drag the widget from the list and when he/she drops it, that widget will appear on the QGraphicsView. Now I want to add a facility that the user can resize the widget with the help of mouse after dropping it on the view. Does anybody have an idea how to do it?

    Thanks in advance.
    Charvi.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Giving user facility to resize widgets run time

    I guess you are using QGraphicsWidget. Then you can alter the size with QGraphicsWidget::resize(). To react on mouse event you can either use QGraphicsScene::mousePressEvent() + QGraphicsScene::mouseMoveEvent() or you can create handler items on the edges of the dropped widget. Johan has an example of the later in his book Foundations of Qt Development.

  3. #3
    Join Date
    Mar 2012
    Location
    India
    Posts
    102
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Giving user facility to resize widgets run time

    Thanks for answering.

    But my problem is a bit different. Like on my mainwindow on the right hand side I have a QWIdgetList wherein I have Items named Line Edit, Text edit, Label and Push Button. Now on the left hand side I have a QGraphicsView. When I drag the name Text Edit from the list and drop it on the QGraphicsView then I create an instance of Text Edit runtime and a text edit is shown at the place of the drop event. Now when i click on the text edit I get a cursor there and the click will be detected as a Text Edit mouse press event and not a QGraphicsView mouse press event. I want 2 things:

    1) I want to change the size of any widget at run time like text edit or label.

    2) I also want to be able to move the widgets around.


    Also in the drop event I have created the instance of the Text Edit by QText Edit. Do you think creating my custom class and then reimplementing some method would help? Do you know any such method?

    Charvi.

  4. #4
    Join Date
    Mar 2012
    Location
    India
    Posts
    102
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Giving user facility to resize widgets run time

    Ok. I tried doing the following.

    For 1) I tried reimplementing the resizeEvent() of the iwdget. But for some reason my resizeEvent() is not being called. Does anybody have any idea when the resizeEvent() of any widget will be called?

    For 2) I tried reimplementing the mousePressEvent and the mouseMoveEvent. In the first one I stored the position of the mouse Press and then int he second one I detected the mouse move event position and simply called the move(new_position - old_position) to move the widget. It works to some extent, the widget does move but not so smoothly there's some problem, it sometimes goes to the top left corner. It just doesn't work correctly some of the times.

    Does anybody have any idea about these?

    Charvi.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Giving user facility to resize widgets run time

    Quote Originally Posted by Charvi View Post
    For 1) I tried reimplementing the resizeEvent() of the iwdget. But for some reason my resizeEvent() is not being called. Does anybody have any idea when the resizeEvent() of any widget will be called?
    When the widget is resized.

    For 2) I tried reimplementing the mousePressEvent and the mouseMoveEvent. In the first one I stored the position of the mouse Press and then int he second one I detected the mouse move event position and simply called the move(new_position - old_position) to move the widget. It works to some extent, the widget does move but not so smoothly there's some problem, it sometimes goes to the top left corner. It just doesn't work correctly some of the times.
    Apparently you are not doing any checks on the data you receive.

    Have you seen the [wiki]Moving widgets[/wiki] article in our wiki?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Giving user facility to resize widgets run time

    How did you implement the resizeEvent function ?
    When you are adding the widget to the scene, it becomes a graphics item. May be you will need to enable QGraphicsItem::ItemIsMovable.

  7. #7
    Join Date
    Mar 2012
    Location
    India
    Posts
    102
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Giving user facility to resize widgets run time

    Quote Originally Posted by wysota View Post
    Have you seen the [wiki]Moving widgets[/wiki] article in our wiki?
    Thanks a ton. The article helped. Now I can move my widgets without any problem.
    Though one quick question. Before reading this article i was using globalPos() to find the position of the event occurrence and then was using it to move the widget. According to the documentation, mapToParent(), used in the article, does the same. Then why is it that the app works fine with the latter and not with the former?

    When the widget is resized.
    Ya but how should the widget be resized? I want a functionality in which the widget should be able to be resized by the user run time with the help of mouse, like we do it in Qt Designer. I don't want to do it through programming.


    Added after 4 minutes:


    Quote Originally Posted by aamer4yu View Post
    When you are adding the widget to the scene, it becomes a graphics item. May be you will need to enable QGraphicsItem::ItemIsMovable.
    I am adding the widgets in the GraphicsView run time, by drag and drop. There is a list of widgets on one side and Qt GraphicsView on the other side. When the user drags and drops the widget name on the graphics view it is replaced by the widget instance. So the widgets are being added run time. And about the ItemIsMovable flag, I think it is true by default.
    Last edited by Charvi; 20th March 2012 at 09:50.

Similar Threads

  1. Replies: 6
    Last Post: 7th February 2012, 02:03
  2. Widgets: Let the user change the size
    By Donner in forum Qt Programming
    Replies: 2
    Last Post: 14th November 2010, 20:13
  3. QSplitter only resize from user input?
    By winston2020 in forum Qt Programming
    Replies: 1
    Last Post: 30th January 2009, 15:50
  4. how do I discard user changes on widgets
    By donglebob in forum Qt Programming
    Replies: 5
    Last Post: 30th December 2008, 07:50
  5. Replies: 3
    Last Post: 3rd September 2008, 16:41

Tags for this Thread

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.