Results 1 to 6 of 6

Thread: Hiding/Showing a layout by pressing a button.

  1. #1
    Join Date
    Jan 2015
    Posts
    3
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Hiding/Showing a layout by pressing a button.

    Hey guys, I've got a question about the grid layout. I've placed there some labels, edit lines and a combo box. I want to hide/show the layout with all that stuff by pressing a button. It should adjust the whole main window according to that hidden/showed layout. Can someone give me an advice how to do it? Thanks.

  2. #2
    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: Hiding/Showing a layout by pressing a button.

    Take a look at the Extension Example for something along these lines.

  3. #3
    Join Date
    Jan 2015
    Posts
    3
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Hiding/Showing a layout by pressing a button.

    Ok, I worked out how to hide all that stuff by pressing one button, but I've got another problem. I don't know how to show them again by pressing the same button. I don't have a clue even after studying that extension example.
    @EDIT:
    My way to do it it's not very effective. I mean look at the code. It should hide and show after pressing the "Inne" button. It shouldn't be "setCheckable(true)." I think the signals are wrong too. Also I should use show() but I don't know how to connect both, hide() and show().

    Qt Code:
    1. void Kalkulator::on_Inne_clicked()
    2. {
    3. przycisk= ui->Inne;
    4. przycisk->setCheckable(true);
    5.  
    6. pierwszy= ui->lineEdit_7;
    7. drugi=ui->lineEdit_8;
    8. trzeci=ui->lineEdit_9;
    9. czwarty=ui->lineEdit_10;
    10. piaty=ui->lineEdit_11;
    11. wybor=ui->comboBox;
    12. jeden=ui->label_10;
    13. dwa=ui->label_11;
    14. trzy=ui->label_12;
    15. cztery=ui->label_13;
    16. piec=ui->label_14;
    17.  
    18. connect(przycisk,SIGNAL(toggled(bool)), pierwszy, SLOT(setVisible(bool)));
    19. connect(przycisk,SIGNAL(toggled(bool)), drugi, SLOT(setVisible(bool)));
    20. connect(przycisk,SIGNAL(toggled(bool)), trzeci, SLOT(setVisible(bool)));
    21. connect(przycisk,SIGNAL(toggled(bool)), czwarty, SLOT(setVisible(bool)));
    22. connect(przycisk,SIGNAL(toggled(bool)), piaty, SLOT(setVisible(bool)));
    23. connect(przycisk,SIGNAL(toggled(bool)), wybor, SLOT(setVisible(bool)));
    24. connect(przycisk,SIGNAL(toggled(bool)), jeden, SLOT(setVisible(bool)));
    25. connect(przycisk,SIGNAL(toggled(bool)), dwa, SLOT(setVisible(bool)));
    26. connect(przycisk,SIGNAL(toggled(bool)), trzy, SLOT(setVisible(bool)));
    27. connect(przycisk,SIGNAL(toggled(bool)), cztery, SLOT(setVisible(bool)));
    28. connect(przycisk,SIGNAL(toggled(bool)), piec, SLOT(setVisible(bool)));
    29.  
    30. pierwszy->hide();
    31. drugi->hide();
    32. trzeci->hide();
    33. czwarty->hide();
    34. piaty->hide();
    35. wybor->hide();
    36. jeden->hide();
    37. dwa->hide();
    38. trzy->hide();
    39. cztery->hide();
    40. piec->hide();
    41.  
    42. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by kielbas99; 26th January 2015 at 01:09. Reason: updated contents

  4. #4
    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: Hiding/Showing a layout by pressing a button.

    All the buttons you want to hide should be put into a dedicated widget and you should be hiding/showing that single widget. Or maybe even you should use QStackedWidget to divide your widgets into pages exactly one of which is visible at a time.
    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.


  5. The following user says thank you to wysota for this useful post:

    kielbas99 (26th January 2015)

  6. #5
    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: Hiding/Showing a layout by pressing a button.

    Not sure how I managed to write this and then not post it a few hours back....

    Here is one approach:
    Qt Code:
    1. class Kalkulator {
    2. ...
    3. private:
    4. void updateUi();
    5. bool m_visible;
    6. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. Kalkulator::Kalkulator():
    2. m_visible(true) // <<< the initial visibility
    3. {
    4. ...
    5. updateUi(); // <<< make the UI match the visibility
    6. }
    7.  
    8. Kalkulator::updateUi()
    9. {
    10. pierwszy->setVisible(m_visible);
    11. drugi->setVisible(m_visible);
    12. ...
    13. }
    14.  
    15. void on_Inne_Clicked()
    16. {
    17. m_visible = !m_visible; // <<< toggle visibility
    18. updateUi(); // <<< make the UI match the visibility
    19. }
    To copy to clipboard, switch view to plain text mode 

    Or even cleaner, put all the hideable widgets inside a single QWidget and simply show or hide that widget. (That's what the example does and wysota suggests)

  7. The following user says thank you to ChrisW67 for this useful post:

    kielbas99 (26th January 2015)

  8. #6
    Join Date
    Jan 2015
    Posts
    3
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Hiding/Showing a layout by pressing a button.

    Thanks. Without you I would be still thinking about a way out. Thanks again for help.

Similar Threads

  1. Hiding and showing the same mainwindow multiple times
    By Charvi in forum Qt Programming
    Replies: 2
    Last Post: 20th June 2012, 12:19
  2. Replies: 1
    Last Post: 9th August 2011, 21:38
  3. Hiding Layout item - Layout does not use available space
    By Asperamanca in forum Qt Programming
    Replies: 0
    Last Post: 27th January 2011, 09:51
  4. Showing and hiding menubar
    By borges in forum Newbie
    Replies: 1
    Last Post: 23rd September 2007, 10:56
  5. Performance in hiding/showing widgets
    By Paalrammer in forum Newbie
    Replies: 12
    Last Post: 14th February 2007, 18:57

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.