Results 1 to 5 of 5

Thread: qwidget how to set visible/hidden ?

  1. #1
    Join Date
    Aug 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default qwidget how to set visible/hidden ?

    Hi everybody.
    My question is this :
    I've a dialog, with buttons and a textedit. I want to set visible/hidden the textedit. The code is this :
    Qt Code:
    1. ...
    2. bigEditor = new QTextEdit;
    3. bigEditor->setPlainText(QDir::currentPath ());
    4. bigEditor->setFont(QFont("Courier", 15, QFont::Bold));
    5.  
    6. quitButton = new QPushButton(tr("&Quit"));
    7. quitButton->setDefault(true);
    8.  
    9. moreButton = new QPushButton(tr("&More"));
    10. moreButton->setCheckable(true);
    11. moreButton->setAutoDefault(false);
    12.  
    13. buttonBox = new QDialogButtonBox(Qt::Horizontal);
    14. buttonBox->addButton(quitButton, QDialogButtonBox::ActionRole);
    15. buttonBox->addButton(moreButton, QDialogButtonBox::ActionRole);
    16.  
    17. connect(moreButton, SIGNAL(clicked()), this, SLOT(Visualizza()));
    18. connect(quitButton, SIGNAL(clicked()), this, SLOT(accept()));
    19.  
    20. extension = new QWidget;
    21. QVBoxLayout *extensionLayout = new QVBoxLayout;
    22. extensionLayout->setMargin(10);
    23. extensionLayout->addWidget(bigEditor);
    24. extension->setLayout(extensionLayout);
    25. extension->hide();
    26.  
    27. QVBoxLayout *mainLayout = new QVBoxLayout;
    28. mainLayout->addWidget(horizontalGroupBox);
    29. mainLayout->addWidget(buttonBox);
    30. mainLayout->addWidget(extension);
    31. setLayout(mainLayout);
    32.  
    33. ....
    34. void Dialog::Visualizza()
    35. {
    36. bool stato = extension->isHidden();
    37. bigEditor->append( "VISUALIZZATO" );
    38. switch (stato)
    39. {
    40. case true:
    41. extension->show();
    42. bigEditor->setVisible(true);
    43. case false:
    44. extension->hide();
    45. bigEditor->setVisible(false);
    46. }
    47. }
    To copy to clipboard, switch view to plain text mode 
    I've posted only the code I tks is important the last code it's for making the rest of Dialog. If is intresting I can post it.

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qwidget how to set visible/hidden ?

    man this is really fun ..
    use "break" in switch and your code work properly ...

    Qt Code:
    1. case true:
    2. printf("the true state returning:%d \n", stato);
    3. extension->show();
    4. bigEditor->setVisible(true);
    5. break;
    6. case false:
    7. printf("false the state returning:%d \n", stato);
    8. extension->hide();
    9. bigEditor->setVisible(false);
    10. break;
    To copy to clipboard, switch view to plain text mode 
    "Behind every great fortune lies a crime" - Balzac

  3. #3
    Join Date
    Aug 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qwidget how to set visible/hidden ?

    SOLVED, I've use a member isHidden().

  4. #4
    Join Date
    Aug 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qwidget how to set visible/hidden ?

    wagmare, tks for you help. I've just solved....
    with if condition.
    By Ricky

  5. #5
    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: qwidget how to set visible/hidden ?

    How about just:
    Qt Code:
    1. bool state = extension->isHidden();
    2. extension->setVisible(state);
    3. bigEditor->setVisible(state);
    To copy to clipboard, switch view to plain text mode 

    You don't need any conditions then.
    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. Promoting the parent QWidget of a QWidget form
    By extrakun in forum Qt Tools
    Replies: 6
    Last Post: 16th April 2010, 14:19
  2. Replies: 0
    Last Post: 11th November 2008, 15:36
  3. Dynamic updates of a QWidget in a QScrollArea
    By plamkata in forum Qt Programming
    Replies: 2
    Last Post: 20th July 2008, 23:45
  4. Error in put one QWidget in another QWidget
    By xjtu in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2008, 16:05
  5. Replies: 3
    Last Post: 8th March 2007, 14:54

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.