Results 1 to 6 of 6

Thread: Handle of MainWindow using CheckBox

  1. #1
    Join Date
    Mar 2010
    Posts
    54
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60

    Default Handle of MainWindow using CheckBox

    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;

    }
    Last edited by kamlmish; 8th December 2010 at 05:06.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Handle of MainWindow using CheckBox

    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.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Handle of MainWindow using CheckBox

    Removed dupe post.

  4. #4
    Join Date
    Mar 2010
    Posts
    54
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60

    Default Re: Handle of MainWindow using CheckBox

    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
    Last edited by kamlmish; 8th December 2010 at 05:23.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Handle of MainWindow using CheckBox

    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.

  6. #6
    Join Date
    Mar 2010
    Posts
    54
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60

    Default Re: Handle of MainWindow using CheckBox

    Thanks
    I was able to make it work
    Thanks a lot

Similar Threads

  1. HOw to handle checkBox event occured in qlistwidget
    By sanket.mehta in forum Qt Programming
    Replies: 0
    Last Post: 16th November 2010, 09:36
  2. checkbox
    By fluefiske in forum Newbie
    Replies: 3
    Last Post: 5th October 2010, 22:41
  3. CheckBox in treeview
    By ansar in forum Qt Programming
    Replies: 2
    Last Post: 16th December 2009, 05:41
  4. checkbox
    By nErnie in forum Qt Programming
    Replies: 1
    Last Post: 25th September 2006, 21:59
  5. checkBox
    By mickey in forum Qt Programming
    Replies: 8
    Last Post: 1st April 2006, 23:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.