Autoadjusting a window by checking / unchecking a checkbox



  • Hi,

    I created an editor (see picture below) and what i want is when the user check the check box, le tabWidget is shown and the window dialog is expanded. And when the checkbox is unchecked, the dialog retrieve exactly his old size. But it doesn't work ...

    !http://www.developpez.net/forums/attachments/p89049d1328204078t/c-cpp/bibliotheques/qt/debuter/redimensionnement-automatique-qdialog-selon-contenu/editeur.png/(Video editor picture)!

    Here is a simplified code :

    @
    class Editeur : public QDialog
    {
    Q_OBJECT

    public:
    Editeur()
    {
    m_pContent = new QWidget(this);

        m_pTimeLine = new QWidget(this);
        m_pTimeLine->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    
        m_pCurrentTime = new QLabel("00:00:00", this);
        m_pCurrentTime->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    
        m_pSlider = new QSlider(Qt::Horizontal, this);
        m_pSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    
        m_pToolBar = new QToolBar("ToolBar", this);
        m_pToolBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    
        m_pCheckBox = new QCheckBox("Montrer onglet");
        m_pCheckBox->setChecked(false);
        m_pCheckBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
        QObject::connect(m_pCheckBox, SIGNAL(stateChanged(int)), this, SLOT(showOrHideTab()));
    
        m_pTabWidget = new QTabWidget(this);
        m_pTabWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
        QWidget * tab1 = new QWidget(m_pTabWidget);
        QHBoxLayout * hboxLayout = new QHBoxLayout;
        QLabel * labelPath = new QLabel("Libelle");
        QLineEdit * lineEdit = new QLineEdit;
        QPushButton * parcourir = new QPushButton("Parcourir");
        hboxLayout->addWidget(labelPath);
        hboxLayout->addWidget(lineEdit);
        hboxLayout->addWidget(parcourir);
        tab1->setLayout(hboxLayout);
        m_pTabWidget->addTab(tab1, "Onglet 1");
        m_pTabWidget->setCurrentIndex(0);
    
        m_pButtonBox = new QDialogButtonBox(this);
        m_pButtonBox->setObjectName(QString::fromUtf8("buttonBox"));
        m_pButtonBox->setOrientation(Qt::Horizontal);
        m_pButtonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
    
        QObject::connect(m_pButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
        QObject::connect(m_pButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
    
        // Content
        QVBoxLayout * globalLayout = new QVBoxLayout(m_pContent);
        globalLayout->addWidget(m_pTimeLine);
        globalLayout->addWidget(m_pCurrentTime, 0, Qt::AlignCenter);
        globalLayout->addWidget(m_pSlider);
        globalLayout->addWidget(m_pToolBar);
        globalLayout->addWidget(m_pCheckBox);
        globalLayout->addWidget(m_pTabWidget);
        globalLayout->addWidget(m_pButtonBox);
    
        setLayout(globalLayout);
    }
    

    public slots:
    void showOrHideTab();

    private:
    QWidget * m_pContent;
    QWidget * m_pTimeLine;
    QSlider * m_pSlider;
    QLabel * m_pCurrentTime;
    QToolBar * m_pToolBar;
    QCheckBox * m_pCheckBox;
    QTabWidget * m_pTabWidget;
    QDialogButtonBox *m_pButtonBox;
    };

    void Editeur::showOrHideTab()
    {
    switch (m_pCheckBox->checkState())
    {
    case Qt::Unchecked:
    m_pCheckBox->setText(tr("Show tabs"));
    m_pTabWidget->hide();
    break;

    case Qt::Checked:
        m_pCheckBox->setText(tr("Hide tabs"));
        m_pTabWidget->show();
        break;
    }
    

    }
    @

    Thanks


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.