Results 1 to 5 of 5

Thread: QSpinBox with checkbox

  1. #1
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default QSpinBox with checkbox

    Hi folks,

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



    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:

    Qt Code:
    1. int x = 50;
    2.  
    3. optionsDlg dlg(this);
    4.  
    5. QListViewItemIterator it (this);
    6. while (it.current())
    7. {
    8. if (!it.current()->parent())
    9. {
    10. SomethingItem *somethingItem = (SomethingItem*) it.current();
    11. QString itemName = it.current()->text (Col_Item_Names);
    12.  
    13. if (somethingItem->getCol_Val() > x )
    14. {
    15. if (dlg.check_item_smaller && dlg.itemBox1)
    16.  
    17. {
    18. dlg.check_item_smaller->setChecked(true);
    19. somethingItem->setVisible(false);
    20. }
    21. else
    22. somethingItem->setVisible(false);
    23. }
    24.  
    25. else if (somethingItem->getCol_Val() < x)
    26. {
    27.  
    28. if(dlg.check_item_greater && dlg.itemBox2)
    29. {
    30.  
    31. dlg.check_item_greater->setChecked(true);
    32. somethingItem->setVisible(true);
    33. }
    34. else
    35. somethingItem->setVisible(false);
    36. }
    37. }
    38. it++;
    39. }
    To copy to clipboard, switch view to plain text mode 

    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
    Love::Peace

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSpinBox with checkbox

    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:
    Qt Code:
    1. if(firstcheck->isChecked() && item->value()<firstspin->value()){
    2. ignoretheitem = true;
    3. }
    4. if(secondcheck->isChecked() && item->value()>secondspin->value()){
    5. ignoretheitem = true;
    6. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default Re: QSpinBox with checkbox

    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,
    Love::Peace

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSpinBox with checkbox

    1. I said it was pseudocode
    2. You probably forgot to include <QSpinBox>

  5. #5
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default Re: QSpinBox with checkbox

    Quote Originally Posted by wysota View Post
    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..
    Love::Peace

Similar Threads

  1. Replies: 3
    Last Post: 1st April 2011, 05:58
  2. QSpinBox and setStylesheet problem
    By Ace-X in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2007, 12:21
  3. float value to Qspinbox
    By nErnie in forum Qt Programming
    Replies: 6
    Last Post: 17th October 2006, 09:16
  4. checkbox
    By nErnie in forum Qt Programming
    Replies: 1
    Last Post: 25th September 2006, 22:59
  5. Problem reimplementing QSpinBox in a custom widget
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2006, 09:12

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.