PDA

View Full Version : Handle of MainWindow using CheckBox



kamlmish
8th December 2010, 04:45
Hi All

I have a small issue where I need to resize the mainwindow using the checkbox. My environment is Linkat( linux) and Qt.
Issue is when I check the checkbox, the window resizes to the size given in isFloating(), but when I uncheck the box, it does not return to isDocked() size
The default size is isDocked();

In the MainWindow class , I have the following code
MainWindow.h
/************************************************** ********/
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
~MainWindow();
public slots:
void isDocked();
void isFloated();
public:
Qt::CheckState state;
QCheckBox *m_CheckBox;
}
/************************************************** **/
MainWindow.cpp
/************************************************** ****/
MainWindow::MainWindow()
{
m_CheckBox = new QCheckBox(this);
m_CheckBox->setGeometry(20,460,270,700);
state = Qt::Unchecked;

connect(m_CheckBox,SIGNAL(clicked()),this,SLOT(isD ocked()),Qt::AutoConnection); connect(m_CheckBox,SIGNAL(clicked()),this,SLOT(isF loated()),Qt::AutoConnection);
}

void MainWindow::isDocked()
{
this->setGeometry(20,460,270,700);
state = Qt::Checked;

}

void MainWindow::isFloated()
{
this->setGeometry(0,0,766,566);
state =Qt::Unchecked;

}

ChrisW67
8th December 2010, 04:58
Use [code] tags in future.

You have connected the clicked() signal to both slots. So, when you click the check box first isDocked() is called, then isFloated(). Consequently, your window always ends up being the "floated" size.

ChrisW67
8th December 2010, 04:59
Removed dupe post.

kamlmish
8th December 2010, 05:10
What needs to be done to make the window return to "docked" size.
Do I need to create a signal and connect it to the "isFloated()"

What needs to be done to make the window return to "docked" size.
Do I need to create a signal and connect it to the "isFloated()"

But the sender has to be the checkbox

ChrisW67
8th December 2010, 05:51
You don't need to create a signal, you just need to sit and think about the logic of what you want to do when the existing signal is received.

Some more hints:
You only need one slot and one signal
The stateChanged() signal might be useful but clicked() can do it too
Your existing "state" member variable is neither useful nor used.

kamlmish
8th December 2010, 06:33
Thanks
I was able to make it work
Thanks a lot