Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 953175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:00:34+00:00 2026-05-16T00:00:34+00:00

Say I have a QHBoxLayout where there are 2 QTextEdit s and between them

  • 0

Say I have a QHBoxLayout where there are 2 QTextEdits and between them a button with an arrow to the right. When you click on the button, the right-side QTextEdit gradually closes by moving the left border until it meets the right one. Simultaneously, the right border of the left QTextEdit takes the place which the right QTextEdit released. And after pressing on the button, the state of the system is coming to the former one.

EDIT: In order to organize this I have done the following:

1) In header file:

class MyWidget : public QWidget
{

    Q_OBJECT

    QTextEdit       *m_textEditor1;
    QTextEdit       *m_textEditor2;
    QPushButton     *m_pushButton;
    QHBoxLayout     *m_layout;
    int              m_deltaX;

public:

    MyWidget(QWidget * parent = 0);


    ~MyWidget(){}


private slots:
    void closeOrOpenTextEdit2(bool isClosing);


};

2) In the source file:

MyWidget::MyWidget(QWidget * parent):QWidget(parent),m_deltaX(0)
{


  m_pushButton = new QPushButton(this);
  m_pushButton->setText(">");
  m_pushButton->setCheckable(true);
  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_layout = new QHBoxLayout;
  m_layout->addWidget(m_textEditor1);
  m_layout->addWidget(m_pushButton);
  m_layout->addWidget(m_textEditor2);

  setLayout(m_layout);
}

void MyWidget::closeOrOpenTextEdit2(bool isClosing)
{
    QPropertyAnimation *animation1 = new QPropertyAnimation(m_textEditor2, "geometry");
    QPropertyAnimation *animation2 = new QPropertyAnimation(m_pushButton, "geometry");
    QPropertyAnimation *animation3 = new QPropertyAnimation(m_textEditor1, "geometry");

    if(isClosing) //close the second textEdit
    {
        m_pushButton->setText("<");

        QRect te2_1 = m_textEditor2->geometry();
        m_deltaX = te2_1.width()-3;
        QRect te2_2(te2_1.x()+m_deltaX, te2_1.y(), 3 ,te2_1.height());

        QRect pb_1 = m_pushButton->geometry();
        QRect pb_2(pb_1.x()+m_deltaX, pb_1.y(), pb_1.width() ,pb_1.height());

        QRect te1_1 = m_textEditor1->geometry();
        QRect te1_2(te1_1.x(), te1_1.y(), te1_1.width()+m_deltaX, te1_1.height());


         //animation->setDuration(10000);
         animation1->setStartValue(te2_1);
         animation1->setEndValue(te2_2);

         animation2->setStartValue(pb_1);
         animation2->setEndValue(pb_2);

         animation3->setStartValue(te1_1);
         animation3->setEndValue(te1_2);
    }
    else //open
    {
       m_pushButton->setText(">");

       QRect te2_1 = m_textEditor2->geometry();
       QRect te2_2(te2_1.x()-m_deltaX, te2_1.y(), 3+m_deltaX ,te2_1.height());

       QRect pb_1 = m_pushButton->geometry();
       QRect pb_2(pb_1.x()-m_deltaX, pb_1.y(), pb_1.width() ,pb_1.height());

       QRect te1_1 = m_textEditor1->geometry();
       QRect te1_2(te1_1.x(), te1_1.y(), te1_1.width()-m_deltaX, te1_1.height());


        //animation->setDuration(10000);
        animation1->setStartValue(te2_1);
        animation1->setEndValue(te2_2);

        animation2->setStartValue(pb_1);
        animation2->setEndValue(pb_2);

        animation3->setStartValue(te1_1);
        animation3->setEndValue(te1_2);

    }
    animation1->start();
    animation2->start();
    animation3->start();
}

EDIT:

And I have the following problem:

When I close the second QTextEdit (by clicking on the button) and resize the MyWidget, then the QTextEdit restores its state (but it should stay closed of course). How can I solve this problem?

Please provide me with a code snippet.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:00:35+00:00Added an answer on May 16, 2026 at 12:00 am

    Here what I wanted:

    Header file

    class MyWidget : public QWidget
    {
    
        Q_OBJECT
    
        QTextEdit       *m_textEditor1;
        QTextEdit       *m_textEditor2;
        QPushButton     *m_pushButton;
        QHBoxLayout     *m_layout;
        QVBoxLayout     *m_buttonLayout;
    
        int              m_deltaX;
        bool             m_isClosed;
    
    
    public:
    
        MyWidget(QWidget * parent = 0);
        ~MyWidget(){}
    
        void resizeEvent( QResizeEvent * event );
    
    private slots:
        void closeOrOpenTextEdit2(bool isClosing);
    
    };
    

    Source file

    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);
      resize(800,500);
    }
    
    void MyWidget::closeOrOpenTextEdit2(bool isClosing)
    {
        m_isClosed = isClosing;
        QPropertyAnimation *animation1 = new QPropertyAnimation(m_textEditor2, "maximumWidth");
    
        if(isClosing) //close the second textEdit
        {
            m_textEditor2->setMaximumWidth(m_textEditor2->width());
    
            int textEdit2_start = m_textEditor2->maximumWidth();
    
            m_deltaX = textEdit2_start;
            int textEdit2_end = 3;
    
    
    
            animation1->setDuration(500);
            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(500);
            animation1->setStartValue(textEdit2_start);
            animation1->setEndValue(textEdit2_end);
    
    
            m_pushButton->setText(">");
    
        }
    
        animation1->start();
    
    }
    
    
    void MyWidget::resizeEvent( QResizeEvent * event )
    {
        if(!m_isClosed)
            m_textEditor2->setMaximumWidth( QWIDGETSIZE_MAX );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have three files (template_*.txt): template_x.txt template_y.txt template_z.txt I want to copy them
Lets say have this immutable record type: public class Record { public Record(int x,
Say I have a couple of basic objects like so: [Serializable] public class Base
say i have a nvarchar field in my database that looks like this 1,
Say I have a class definition: class CustomClass { int member; }; Why is
Say I have real, dimension(0:100) :: realResults and I want to iterate over realResults
Say I have the following: namespace SomeProject { public interface ISomething { string SomeMethod();
Say we have two tables in an MS Access db: Service Users: | ID
Say I have an ASP.Net MVC webiste hosted at www.somedomain.com. Now I am interested
Say we have an out-proc COM server and a client. The client calls a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.