Results 1 to 6 of 6

Thread: how do I discard user changes on widgets

  1. #1
    Join Date
    Jul 2008
    Posts
    66
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default how do I discard user changes on widgets

    Hi,

    I have a QDialog-instance in my MainProgram, which is made for user settings.
    It has TableWidgets and ComboBox'es with default values.

    The user can make some changes on these widgets values and click SAVE to leave, but
    when the user clicks cancel...the whole values of the widgets must be set back to the state before.

    The actual problem is that after clicking "cancel" all changes to the widgets are saved.

    How can I do that restoring of the widgets content?

  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: how do I discard user changes on widgets

    Quote Originally Posted by donglebob View Post
    The actual problem is that after clicking "cancel" all changes to the widgets are saved.
    That's the point. Simply don't save changes after cancel is pressed. Use exec and have a look at QDialog::DialogCode.


    Lykurg

  3. The following user says thank you to Lykurg for this useful post:

    donglebob (30th December 2008)

  4. #3
    Join Date
    Jul 2008
    Posts
    66
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how do I discard user changes on widgets

    Hi,

    I don't save anything.

    My QDialog-Class X is a member of my MainProgram. I create it dynamically in its Ctor.
    When the user wants to enter X he clicks on a button and X->exec() will be called.

    The dialog X appears, the user changes something (content) on the widgets Y (TableWidget) and Z (ComboBox). Thats all. After closing the X dialog it returns back to the callers slot.

    I know that I can see what the result of X-exec() is
    Accept: 1
    Reject: 0

    But the main question is...who saves the dialog content?
    Not me... I don't have an explicit saving method or sth like that.

    Maybe I should destroy every time the instance of X ??
    But that would be ugly...there must be another way of doing this.

  5. #4
    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: how do I discard user changes on widgets

    You will need to save the settings somewhere,, either in member variable in program, or in file. How do u provide values to the dialog ?

  6. The following user says thank you to aamer4yu for this useful post:

    donglebob (30th December 2008)

  7. #5
    Join Date
    Jul 2008
    Posts
    66
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how do I discard user changes on widgets

    The values for the dialog are set by the parent window.
    The widgets of the config-dialog-class are public.

    If you mean with settings "QSettings", I tried it but I think its just for the position and size of the window, not the content. It failed for me...don't know what I have done wrong.

  8. #6
    Join Date
    Jul 2008
    Posts
    66
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how do I discard user changes on widgets

    Now I solved it with the following steps:

    - I added my dialog-class the equal-operator
    - I used the dialog codes

    First I made a backup of the object, before executing exec().
    If the user "rejects" the backuped copy will be recovered...

    Thanks again guys...

Similar Threads

  1. Logging Qt User Actions
    By Frank J. Lhota in forum Qt Programming
    Replies: 14
    Last Post: 30th May 2014, 21:36
  2. Mac OS X Top-Level Transparent Widgets
    By tinsuke in forum Qt Programming
    Replies: 0
    Last Post: 17th October 2008, 16:01
  3. Upper limit on number of widgets?
    By jdiewald in forum Qt Programming
    Replies: 1
    Last Post: 29th September 2008, 23:00
  4. Replies: 2
    Last Post: 16th May 2008, 14:39
  5. Discard user input events in QEventLoop.
    By Ben.Hines in forum Qt Programming
    Replies: 2
    Last Post: 17th April 2006, 20:49

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
  •  
Qt is a trademark of The Qt Company.