#include "mainwindow.h" MyWidget::MyWidget(QWidget * parent):QWidget(parent),m_deltaX(0) { m_pushButton = new QPushButton(this); m_pushButton->setText(">"); m_pushButton->setCheckable(true); m_pushButton->setFixedSize(16,16); connect(m_pushButton, SIGNAL(clicked(bool)), this, SLOT(closeOrOpenTextEdit2(bool))); m_textEditor1 = new QTextEdit(this); m_textEditor1->setText("AAAAA AAAAAAAAAAA AAAAAAAAAAA AAAAAAA AAAAAAAAAAA AAAAAAAAAAA AA"); m_textEditor2 = new QTextEdit(this); m_buttonLayout = new QVBoxLayout(); m_buttonLayout->addWidget(m_pushButton); m_buttonLayout->addItem( new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding) ); m_layout = new QHBoxLayout; m_layout->addWidget(m_textEditor1, 10); m_layout->addSpacing(15); m_layout->addLayout(m_buttonLayout); m_layout->setSpacing(0); m_layout->addWidget(m_textEditor2, 4); setLayout(m_layout); } void MyWidget::closeOrOpenTextEdit2(bool isClosing) { m_isClosed = isClosing; QPropertyAnimation *animation1 = new QPropertyAnimation(m_textEditor2, "maximumWidth"); if(isClosing) //close the second textEdit { int textEdit2_start = m_textEditor2->maximumWidth(); m_deltaX = textEdit2_start; int textEdit2_end = 3; animation1->setDuration(1); animation1->setStartValue(textEdit2_start); animation1->setEndValue(textEdit2_end); m_pushButton->setText("<"); } else //open { int textEdit2_start = m_textEditor2->maximumWidth(); int textEdit2_end = m_deltaX; animation1->setDuration(2000); animation1->setStartValue(textEdit2_start); animation1->setEndValue(textEdit2_end); m_pushButton->setText(">"); } animation1->start(); }