PDA

View Full Version : qwidget how to set visible/hidden ?



ricky
10th August 2009, 21:28
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 :


...
bigEditor = new QTextEdit;
bigEditor->setPlainText(QDir::currentPath ());
bigEditor->setFont(QFont("Courier", 15, QFont::Bold));

quitButton = new QPushButton(tr("&Quit"));
quitButton->setDefault(true);

moreButton = new QPushButton(tr("&More"));
moreButton->setCheckable(true);
moreButton->setAutoDefault(false);

buttonBox = new QDialogButtonBox(Qt::Horizontal);
buttonBox->addButton(quitButton, QDialogButtonBox::ActionRole);
buttonBox->addButton(moreButton, QDialogButtonBox::ActionRole);

connect(moreButton, SIGNAL(clicked()), this, SLOT(Visualizza()));
connect(quitButton, SIGNAL(clicked()), this, SLOT(accept()));

extension = new QWidget;
QVBoxLayout *extensionLayout = new QVBoxLayout;
extensionLayout->setMargin(10);
extensionLayout->addWidget(bigEditor);
extension->setLayout(extensionLayout);
extension->hide();

QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(horizontalGroupBox);
mainLayout->addWidget(buttonBox);
mainLayout->addWidget(extension);
setLayout(mainLayout);

....
void Dialog::Visualizza()
{
bool stato = extension->isHidden();
bigEditor->append( "VISUALIZZATO" );
switch (stato)
{
case true:
extension->show();
bigEditor->setVisible(true);
case false:
extension->hide();
bigEditor->setVisible(false);
}
}

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.

wagmare
11th August 2009, 07:11
man this is really fun ..
use "break" in switch and your code work properly ... :)


case true:
printf("the true state returning:%d \n", stato);
extension->show();
bigEditor->setVisible(true);
break;
case false:
printf("false the state returning:%d \n", stato);
extension->hide();
bigEditor->setVisible(false);
break;

ricky
11th August 2009, 07:44
SOLVED, I've use a member isHidden().

ricky
12th August 2009, 07:54
wagmare, tks for you help. I've just solved....
with if condition.
By Ricky

wysota
12th August 2009, 08:07
How about just:

bool state = extension->isHidden();
extension->setVisible(state);
bigEditor->setVisible(state);

You don't need any conditions then.