Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23

Thread: Changing text of button in no relation to button

  1. #21
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Changing text of button in no relation to button

    It appears you want the user to push button 1 to select a file. You then change the label on button 1 to the path the user selected. You then expect the user to push button 2 to process the file selected when they pushed button 1.

    Quoting out of order:
    Quote Originally Posted by Sabre Runner View Post
    What I'd like to do is to change the text of button 1 if and only if button 2's operation has reached the loaded successfully part.
    Then why do you set it in the handler for the pushButton1 clicked signal? Line 5 in this chunk:
    Qt Code:
    1. void Window::on_pushButton1_clicked()
    2. {
    3. path = QFileDialog::getOpenFileName(this, tr("Open File..."), path,tr("Files (*.*)"));
    4. path = QDir::toNativeSeparators(path);
    5. pushButton1.setText(path);
    6. }
    To copy to clipboard, switch view to plain text mode 
    This is the button that preps the path to be used to load the file from.
    should probably be after line 16 of this chunk where the processing has been successful after the user presses button 2:
    Qt Code:
    1. void Window::on_pushButton2_clicked()
    2. {
    3. try something...
    4. catch one exception...
    5. {
    6. output error 1...
    7. }
    8. catch second exception...
    9. {
    10. output error 2...
    11. }
    12. catch all other exceptions...
    13. {
    14. output generic error...
    15. }
    16. QMessageBox::information(this,tr("Loaded"),tr("Loaded Successfully"));
    17. perform some other operations and configurations for the future...
    18. }
    To copy to clipboard, switch view to plain text mode 
    You also need to ensure that button 2 cannot be pressed unless button 1 has been AND the user did not cancel the file selection. Something has to reset button 1's label too I guess.

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

    Default

    I hate to keep suggesting "printf-style" debugging, but here's another case where it would probably shed light on what's going on. Placing output statements in your code just prior to your call to button.setText() would allow you to see if that portion of your code is getting called in the first place, and if so to dump the value of local variables that may be related to your problems.

    The preferred method for determining such things, of course, is to run in a debugger, but for simple problems it's often best to use simple solutions.

    Also, I should point out that trying to display paths on buttons is a remarkably poor UI decision. As soon as you hit a case where the path is too long to show on the button, and you realize that you can't scroll to see the other end of it, the design breaks and breaks badly. And that's probably going to happen within minutes of actual use.

    Part of your job as a software engineer will be to bring such matters to a client's attention before they cause such problems, and to provide reasonable alternative solutions.
    Last edited by wysota; 23rd September 2010 at 08:11.

  3. #23
    Join Date
    Sep 2010
    Location
    Israel
    Posts
    24
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Changing text of button in no relation to button

    Yes. I even added that same set text command at the start of the program but it doesn't change the button.
    Do I need to update or repaint? And if so, how? Because I tried those some times and they didn't work either.

Similar Threads

  1. Replies: 6
    Last Post: 21st August 2010, 21:09
  2. Replies: 1
    Last Post: 2nd August 2010, 05:40
  3. Button icon and text
    By electronicboy in forum Qt Programming
    Replies: 5
    Last Post: 9th October 2009, 22:27
  4. changing color of push button
    By babu198649 in forum Newbie
    Replies: 1
    Last Post: 2nd March 2008, 12:55

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.