Results 1 to 5 of 5

Thread: How to show and hide Button when i created.

  1. #1
    Join Date
    Mar 2011
    Location
    Việt Nam
    Posts
    8
    Thanks
    3
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default How to show and hide Button when i created.

    - Create Layout:

    Qt Code:
    1. void Schedule::createLayout()
    2. {
    3. QVBoxLayout *mainLayout = new QVBoxLayout();
    4. QGridLayout *daysLayout = new QGridLayout();
    5. QWidget *viewport = new QWidget();
    6. mainLayout->addWidget(viewport);
    7.  
    8. Token *label = new Token(this);
    9. label->setAlignment(Qt::AlignLeft);
    10. QList<Token *> cwList;
    11. cwList.append(label);
    12. daysLayout->addWidget(label);
    13.  
    14.  
    15. for (int i = 0; i < 5; i++ )
    16. {
    17. Button *label = new Button(this);
    18. label->setAlignment(Qt::AlignLeft);
    19. label->setOptimumSize(299, 15);
    20. label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    21. SchedulesList.append(label);
    22. daysLayout->addWidget(label);
    23. }
    24.  
    25. daysLayout->setSpacing(1);
    26. daysLayout->setContentsMargins(0,0,0,0);
    27. daysLayout->setAlignment(Qt::AlignCenter);
    28. viewport->setLayout(daysLayout);
    29.  
    30. mainLayout->setSpacing(0);
    31. mainLayout->setContentsMargins(0,0,0,0);
    32. mainLayout->setAlignment(Qt::AlignCenter);
    33. setLayout(mainLayout);
    34. }
    To copy to clipboard, switch view to plain text mode 
    - i want update layout can show and hide button.
    i use:
    Qt Code:
    1. QLayoutItem *Item = NULL;
    2. for (int i = 0; i < 5; i++)
    3. {
    4. Item = daysLayout->itemAt(i);
    5. if (Item)
    6. {
    7. Item->widget()->hide();
    8. Item->widget()->adjustSize();
    9. Item->widget()->updateGeometry();
    10. }
    11. }
    12. daysLayout->update();
    To copy to clipboard, switch view to plain text mode 

    But i can't show them again.
    How to do this??
    Many thank!!!
    Last edited by high_flyer; 14th March 2011 at 10:29. Reason: code tags

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to show and hide Button when i created.

    But i can't show them again.
    Where is the code for showing the buttons again?
    You didn't post it.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Mar 2011
    Location
    Việt Nam
    Posts
    8
    Thanks
    3
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: How to show and hide Button when i created.

    This code Show:

    Qt Code:
    1. std::vector<CScheduleItem*>::iterator it;
    2. QLayoutItem *Item = NULL;
    3. int i = 0;
    4. for (it = g_Gadget->GetPIMLookData()->m_vecShedules.begin(); it != g_Gadget->GetPIMLookData()->m_vecShedules.end(); it++)
    5. {
    6. Item = daysLayout->itemAt(i);
    7. Item->widget()->show();
    8. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by high_flyer; 15th March 2011 at 10:55. Reason: code tags

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to show and hide Button when i created.

    Where is this code?
    If you put a break point in the for loop, does it get caught?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Mar 2011
    Location
    Việt Nam
    Posts
    8
    Thanks
    3
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: How to show and hide Button when i created.

    Many thanks, My application worked.
    - The first Create:
    Qt Code:
    1. Token *label = new Token(this);
    2. label->setAlignment(Qt::AlignTop);
    3. label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    4. cwList.append(label);
    5. daysLayout->addWidget(label);
    6.  
    7. for (int i = 0; i < 5; i++)
    8. {
    9. Button *label = new Button(this);
    10. label->setAlignment(Qt::AlignTop);
    11. label->setOptimumSize(299, 15);
    12. label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    13. SchedulesList.append(label);
    14. daysLayout->addWidget(label);
    15. }
    16. for (int i = 1; i < daysLayout->count(); i++)
    17. {
    18. daysLayout->itemAt(i)->widget()->hide();
    19. }
    To copy to clipboard, switch view to plain text mode 
    - After i show this:
    Qt Code:
    1. int nCount = g_Gadget->GetPIMLookData()->m_vecShedules.size();
    2. std::vector<CScheduleItem*>::iterator it;
    3. int i = 0;
    4. int j = 1;
    5. //daysLayout->itemAt(0)->widget()->show();
    6. for (i; i < 5; i++)
    7. {
    8. if (i < nCount)
    9. {
    10. if (!daysLayout->itemAt(i+1)->widget()->isVisible())
    11. daysLayout->itemAt(i+1)->widget()->show();
    12. j++;
    13. }
    14. if (j >= nCount+1 && i >= nCount)
    15. {
    16. if (daysLayout->itemAt(i+1)->widget()->isVisible())
    17. daysLayout->itemAt(i+1)->widget()->hide();
    18. }
    19. if (nCount == 0)
    20. {
    21. if (!daysLayout->itemAt(1)->widget()->isVisible())
    22. daysLayout->itemAt(1)->widget()->show();
    23. }
    24. }
    25. updateGeometry();
    26. if (g_Gadget->bRefresh == true)
    27. animateTop();
    To copy to clipboard, switch view to plain text mode 
    Last edited by vudvpro; 25th March 2011 at 09:56.

Similar Threads

  1. Replies: 10
    Last Post: 20th April 2015, 22:24
  2. Hide/show the Cancel button in a QProgressDialog
    By Vankata in forum Qt Programming
    Replies: 9
    Last Post: 24th February 2011, 20:43
  3. how to show an app if it manually hide
    By jthacker in forum Qt Programming
    Replies: 1
    Last Post: 26th March 2010, 13:02
  4. Replies: 5
    Last Post: 21st November 2007, 09:51
  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.