Can't hide group box in Qt
-
wrote on 12 Jul 2014, 09:00 last edited by
I'm learning GUI programming with qt. I have a problem with Shape-Changing Dialogs. Like this:
!http://i.stack.imgur.com/fTzzJ.jpg(blah)!
To do so, I added some signal-slot, like
@connect(ui->pbMore,SIGNAL(toggled(bool)),ui->gbSecond,SLOT(setShown(bool)));@but it ain't work. I tried
@setVisible(bool)@
or set the connection on the GUI but no luck either.
This is an example from the book C++ GUI Programming with Qt 4, Second Edition. They do the same way with me. So what's my mistake?
Edit: add ui file and codes.
dialogexpand.h
@#ifndef DIALOGEXPAND_H
#define DIALOGEXPAND_H#include <QDialog>
namespace Ui {
class DialogExpand;
}class DialogExpand : public QDialog
{
Q_OBJECTpublic:
explicit DialogExpand(QWidget *parent = 0);
~DialogExpand();private:
Ui::DialogExpand *ui;
public:
void SortDialog(QWidget *parent = 0);
void setColumnRange(QChar first, QChar last);
};@
dialogexpand.cpp@#include "dialogexpand.h"
#include "ui_dialogexpand.h"DialogExpand::DialogExpand(QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogExpand)
{
ui->setupUi(this);connect(ui->pbMore,SIGNAL(toggled(bool)),ui->gSec,SLOT(setVisible(bool))); connect(ui->pbMore,SIGNAL(toggled(bool)),ui->gbThird,SLOT(setShown(bool)));
// ui->gbThird->hide();
// ui->gSec->hide();
SortDialog();
}DialogExpand::~DialogExpand()
{
delete ui;
}void DialogExpand::SortDialog(QWidget *parent)
{// ui->gSec->hide();
// ui->gbThird->hide();
layout()->setSizeConstraint(QLayout::SetFixedSize);
setColumnRange('A', 'Z');
}void DialogExpand::setColumnRange(QChar first, QChar last)
{
ui->cbFirstColumn->clear();
ui->cbSecColumn->clear();
ui->cbSecColumn_2->clear();
ui->cbFirstColumn->addItem(tr("None"));
ui->cbSecColumn->addItem(tr("None"));
ui->cbFirstColumn->setMinimumSize(
ui->cbSecColumn->sizeHint());
QChar ch = first;
while (ch <= last) {
ui->cbFirstColumn->addItem(QString(ch));
ui->cbSecColumn->addItem(QString(ch));
ui->cbSecColumn_2->addItem(QString(ch));
ch = ch.unicode() + 1;
}
}@Edit: I found the answer "here":http://www.qtcentre.org/threads/51981-Shape-Changing-Dialog , just set the button more checkable
1/1