PDA

View Full Version : QSpinBox with checkbox



:db:sStrong
17th January 2007, 10:16
Hi folks,

i have a problem regarding Qspinbox in combination with checkbox.. this is an example of my form :

http://img136.imageshack.us/img136/208/formam0.jpg

so as u see i want to click on the checkbox and chose a number which is smaller or equal to something in qspinbox .. on clicking the ok button, my code list only the items with a value or smaller than the chosen number in qspinbox on screen.. i dont know how to compare the value in qspinbox with the value of the items on my screen in my code i do it like this but it doesnt work:


int x = 50;

optionsDlg dlg(this);

QListViewItemIterator it (this);
while (it.current())
{
if (!it.current()->parent())
{
SomethingItem *somethingItem = (SomethingItem*) it.current();
QString itemName = it.current()->text (Col_Item_Names);

if (somethingItem->getCol_Val() > x )
{
if (dlg.check_item_smaller && dlg.itemBox1)

{
dlg.check_item_smaller->setChecked(true);
somethingItem->setVisible(false);
}
else
somethingItem->setVisible(false);
}

else if (somethingItem->getCol_Val() < x)
{

if(dlg.check_item_greater && dlg.itemBox2)
{

dlg.check_item_greater->setChecked(true);
somethingItem->setVisible(true);
}
else
somethingItem->setVisible(false);
}
}
it++;
}

with getCol_Val() it compare if the numbers in col are smaller than 50 then show the items. but i want to do this with that QspinBox in the form. i want to chose a number is qspinbox and then comapre with getCol_Val()..

can someone look at the code?
thanks in advance

wysota
17th January 2007, 10:37
The code is somewhat cluttered, it's hard to say what each variables represent... Anyway... you can get the value in the spinbox by using QSpinBox::value() and the value of the checkbox using QCheckBox::isChecked(). Then you can make an if statement that checks whether the checkbox is checked and if the item should be accepted. Pseudo code follows:

if(firstcheck->isChecked() && item->value()<firstspin->value()){
ignoretheitem = true;
}
if(secondcheck->isChecked() && item->value()>secondspin->value()){
ignoretheitem = true;
}

:db:sStrong
17th January 2007, 11:09
wysota,
i have used ur code but i get errors, this is how i did it


optionsDlg dlg(this);

if (dlg.firstCheckBox->isChecked() &&
item->getCol_Val() > dlg.spinBox1->value() )
{

item->setVisible(true);

}

if (dlg.secondCheckBox->isChecked()
&& item->getCol_Val() < dlg.spinBox2->value())
{
item->setVisible(true);
}


i get these errors:


: error C2027: use of undefined type 'QSpinBox'
: error C2227: left of '->value' must point to class/struct/union
: error C2027: use of undefined type 'QSpinBox'
: see declaration of 'QSpinBox'
: error C2227: left of '->value' must point to class/struct/union

i have linked my dialogu with my code,

wysota
17th January 2007, 11:16
1. I said it was pseudocode
2. You probably forgot to include <QSpinBox>

:db:sStrong
17th January 2007, 13:22
1. I said it was pseudocode
2. You probably forgot to include <QSpinBox>

jah thanks i had forgotten to include <Qspinbox.h>

but it doesnt work yet..