Results 1 to 3 of 3

Thread: Improper size issue in QWidget::sizeHint()

  1. #1
    Join Date
    Jun 2008
    Posts
    25
    Thanks
    9
    Thanked 1 Time in 1 Post

    Unhappy Improper size issue in QWidget::sizeHint()

    I am using QT 4.5.0.
    I am using a QWidget with 10 checkboxes. 5 of these checkboxes need to be show/hide dynamically depending on certain conditions.
    When i hide those 5 check boxes the QWidget is not getting self adjusted.

    I checked the sizeHint(), which is not getting self adjusted.

    In my case the widget is adjusting the visible 5 checkbox into the area which is used for showing the 10 checkboxs.

    What all may be the possible reasons which prevent the proper resizing of the QWidget ?

    Here is a sample code which i tried within a button click SLOT.

    QSize prefSize = QDialog::sizeHint();
    wholeWordsCheckBox->setVisible(false);
    backwardCheckBox->setVisible(false);
    searchSelectionCheckBox->setVisible(false);
    prefSize = QDialog::sizeHint();

    here the sizeHint() is working when the checkboxes are set as visible, but NOT working when the checkboxes are set as hidden.
    Last edited by George Neil; 22nd September 2009 at 09:56.

  2. #2
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: Improper size issue in QWidget::sizeHint()

    Did u try QWidget::adjustSize()?

  3. #3
    Join Date
    Jun 2008
    Posts
    25
    Thanks
    9
    Thanked 1 Time in 1 Post

    Default Re: Improper size issue in QWidget::sizeHint()

    yes actually my requirement is to make use of the QWidget::adjustSize(). But that is NOT working because sizeHint is NOT correct.

    I have tried the following sample code example.

    #include <QtGui>

    #include "finddialog.h"

    //! [0]
    FindDialog::FindDialog(QWidget *parent)
    : QDialog(parent)
    {
    label = new QLabel(tr("Find &what:"));
    lineEdit = new QLineEdit;
    label->setBuddy(lineEdit);

    caseCheckBox = new QCheckBox(tr("Match &case"));
    fromStartCheckBox = new QCheckBox(tr("Search from &start"));
    fromStartCheckBox->setChecked(true);

    //! [1]
    findButton = new QPushButton(tr("&Find"));
    findButton->setDefault(true);

    moreButton = new QPushButton(tr("&More"));
    moreButton->setCheckable(true);
    //! [0]
    moreButton->setAutoDefault(false);

    buttonBox = new QDialogButtonBox(Qt::Vertical);
    buttonBox->addButton(findButton, QDialogButtonBox::ActionRole);
    buttonBox->addButton(moreButton, QDialogButtonBox::ActionRole);
    //! [1]

    //! [2]
    extension = new QWidget;

    wholeWordsCheckBox = new QCheckBox(tr("&Whole words"));
    backwardCheckBox = new QCheckBox(tr("Search &backward"));
    searchSelectionCheckBox = new QCheckBox(tr("Search se&lection"));
    //! [2]

    //! [3]
    // connect(moreButton, SIGNAL(toggled(bool)), extension, SLOT(setVisible(bool)));
    connect(moreButton, SIGNAL(clicked()), this, SLOT(onClickMore()));

    QVBoxLayout *extensionLayout = new QVBoxLayout;
    extensionLayout->setMargin(0);
    extensionLayout->addWidget(wholeWordsCheckBox);
    extensionLayout->addWidget(backwardCheckBox);
    extensionLayout->addWidget(searchSelectionCheckBox);
    extension->setLayout(extensionLayout);
    //! [3]

    //! [4]
    QHBoxLayout *topLeftLayout = new QHBoxLayout;
    topLeftLayout->addWidget(label);
    topLeftLayout->addWidget(lineEdit);

    QVBoxLayout *leftLayout = new QVBoxLayout;
    leftLayout->addLayout(topLeftLayout);
    leftLayout->addWidget(caseCheckBox);
    leftLayout->addWidget(fromStartCheckBox);
    leftLayout->addStretch(1);

    QGridLayout *mainLayout = new QGridLayout;
    mainLayout->setSizeConstraint(QLayout::SetFixedSize);
    mainLayout->addLayout(leftLayout, 0, 0);
    mainLayout->addWidget(buttonBox, 0, 1);
    mainLayout->addWidget(extension, 1, 0, 1, 2);
    setLayout(mainLayout);

    setWindowTitle(tr("Extension"));
    //! [4] //! [5]
    // extension->hide();
    }

    void FindDialog:nClickMore()
    {
    QSize prefSize = sizeHint();
    wholeWordsCheckBox->setVisible(!wholeWordsCheckBox->isVisible());
    backwardCheckBox->setVisible(!backwardCheckBox->isVisible());
    searchSelectionCheckBox->setVisible(!searchSelectionCheckBox->isVisible());
    prefSize = sizeHint();
    }

Similar Threads

  1. QLabel size policy
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2007, 17:57
  2. The issue on Form's size
    By adorp in forum Qt Programming
    Replies: 2
    Last Post: 23rd July 2007, 18:30
  3. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 22:14

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.