Results 1 to 10 of 10

Thread: Hide/show the Cancel button in a QProgressDialog

  1. #1
    Join Date
    Aug 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Hide/show the Cancel button in a QProgressDialog

    I have a function that does series of actions, e.g. loading, processing and sending data, for several object instances in a loop. I use a QProgressDialog to display the current progress and interrupt it if necessary. However, during the data sending, due to particularities of the receiving side, it is extremely problematic to interrupt, so I would like to hide temporarily the Cancel button and to show it during the other steps.
    The best that I did is the following:

    for(i=0; i<N; i++) {
    //loading
    progress.setCancelButton(new QPushButton("Cancel"));
    ...
    //processing
    ...
    //sending
    progress.setCancelButton(0);
    ...
    }

    The first loading is ok. However, after the button disappears during the first sending, it never appears there where it was. I don't have any idea how to place it anywhere, since I don't have any access to it?

    Is there any solution? Thanks!

  2. #2
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Hide/show the Cancel button in a QProgressDialog

    try reading this,

    setCancelButton

  3. #3
    Join Date
    Aug 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Hide/show the Cancel button in a QProgressDialog

    Hmm... this is exactly what I used! setCancelButton(0) hides (it actually deletes) the button but the problem comes after that, when I create a new Cancel button. It appears at (0,0) in the dialog window, and I don't know how to move it there, where the previous one was. The code is functional, but it looks ugly

  4. #4
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Hide/show the Cancel button in a QProgressDialog

    I would suggest to put the logic inside the slot QProgressDialog::cancel () such that the functionality of Cancel is ignored. Even if you press 'Cancel' button nothing will happen. Not intuitive though!

  5. #5
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Hide/show the Cancel button in a QProgressDialog

    In that case it might be better to hold a QPointer<PushButton> instead of ignoring the action.
    After looking into the qt source I think that the relayouting is missing. (in the qt source). You could check this if you trigger a resizeEvent for the Dialog.

  6. #6
    Join Date
    Aug 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Hide/show the Cancel button in a QProgressDialog

    Thanks guys!
    I found a solution and here it is:

    QList<QPushButton *> L=progressDialog.findChildren<QPushButton *>();
    L.at(0)->hide();
    L.at(0)->show();

    Best regards!

  7. #7
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Hide/show the Cancel button in a QProgressDialog

    If QProgressDialog and the 'Cancel' button shares the parent-child relationship you can use findChild to get the QObject and do QObject casting to get the pushbutton*. Then you can use QWidget::geometry() to get the co-ordinates. Save it and use the same for your logic.

  8. #8
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Hide/show the Cancel button in a QProgressDialog

    I'd suggest disabling the button rather than hiding it. Users are normally happiest when the UI changes as little as possible, and keeping the button displayed but grayed out doesn't force a re-layout to occur.

  9. #9
    Join Date
    Aug 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Hide/show the Cancel button in a QProgressDialog

    Sure! You're right!

  10. #10
    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: Hide/show the Cancel button in a QProgressDialog

    Furthermore if you use setCancelButton() to set a new button, you don't need qFindChild to find it later. Just do it once before you enter the loop.
    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.


Similar Threads

  1. Replies: 10
    Last Post: 20th April 2015, 22:24
  2. Replies: 1
    Last Post: 17th February 2010, 23:17
  3. QDialog, editingFinished, and Cancel Button.
    By jeffpogo in forum Qt Programming
    Replies: 8
    Last Post: 3rd June 2009, 03:22
  4. How to show QProgressDialog without cancel button
    By rajesh in forum Qt Programming
    Replies: 1
    Last Post: 30th January 2007, 09:53
  5. Show or hide a form
    By Gayathri in forum Newbie
    Replies: 11
    Last Post: 17th November 2006, 12:39

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.