Results 1 to 7 of 7

Thread: Check Box problem

  1. #1
    Join Date
    Feb 2006
    Posts
    42
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Check Box problem

    strange2.gif
    Any Idea how to draw this controle? It looks like check buttons on QTextEdit ? I tried to write code to achieve same look and feel ,

    #include <QApplication>
    #include <QtGui>
    int main(int argc, char *argv[])
    {
    QApplication myapp(argc,argv);

    QWidget *mywidget= new QWidget;
    QTextEdit *myedit = new QTextEdit(mywidget);
    QCheckBox *one= new QCheckBox("hotels",myedit);
    QCheckBox *two= new QCheckBox("Restaurants & Cafes",myedit);
    QCheckBox *three= new QCheckBox("Bars,Pubs & Clubs",myedit);
    QCheckBox *four= new QCheckBox("Trips & Activities",myedit);
    QCheckBox *five= new QCheckBox("Sites & Attractions",myedit);
    QCheckBox *six= new QCheckBox("Churches & Temples",myedit);
    QCheckBox *seven= new QCheckBox("Historic Buildings",myedit);
    QCheckBox *eight= new QCheckBox("Museums",myedit);
    QCheckBox *nine= new QCheckBox("Art Galleries",myedit);
    QCheckBox *ten= new QCheckBox("Cinemas",myedit);
    QCheckBox *eleven= new QCheckBox("Theater",myedit);
    QVBoxLayout *lay= new QVBoxLayout;

    lay->addWidget(one);
    lay->addWidget(two);
    lay->addWidget(three);
    lay->addWidget(four);
    lay->addWidget(five);
    lay->addWidget(six);
    lay->addWidget(seven);
    lay->addWidget(eight);
    lay->addWidget(nine);
    lay->addWidget(ten);
    lay->addWidget(eleven);

    myedit->setLayout(lay);
    mywidget->setGeometry(10,10,20,20);

    mywidget->show();

    return myapp.exec();

    }
    But dialog color appear behind the caption of check Box can some body explain how to get rid of this color/ to get same look and feel

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Check Box problem

    Quote Originally Posted by Seema Rao
    Any Idea how to draw this controle? It looks like check buttons on QTextEdit ? I tried to write code to achieve same look and feel
    Use QListView or QListWidget with checkable items.

  3. #3
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Check Box problem

    You could use a QScrollArea too, inserting first all the check boxes in a widget...

  4. #4
    Join Date
    Feb 2006
    Posts
    42
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Check Box problem

    Here is the full code with the modification suggested by you guys, but the problem is items appear multiple times when I resize the window. Am I wrong here ?

    #include <QApplication>
    #include <QtGui>

    int main(int argc, char *argv[])
    {
    QApplication myapp(argc,argv);

    QWidget *mywidget= new QWidget;
    QListWidget *myedit = new QListWidget(mywidget);
    QListWidgetItem *one= new QListWidgetItem("hotels",myedit);
    one->setCheckState(Qt::Unchecked);
    QListWidgetItem *two= new QListWidgetItem("Restaurants & Cafes",myedit);
    two->setCheckState(Qt::Unchecked);
    QListWidgetItem *three= new QListWidgetItem("Bars,Pubs & Clubs",myedit);
    three->setCheckState(Qt::Unchecked);
    QListWidgetItem *four= new QListWidgetItem("Trips & Activities",myedit);
    four->setCheckState(Qt::Unchecked);
    QListWidgetItem *five= new QListWidgetItem("Sites & Attractions",myedit);
    five->setCheckState(Qt::Unchecked);
    QListWidgetItem *six= new QListWidgetItem("Churches & Temples",myedit);
    six->setCheckState(Qt::Unchecked);
    QListWidgetItem *seven= new QListWidgetItem("Historic Buildings",myedit);
    seven->setCheckState(Qt::Unchecked);
    QListWidgetItem *eight= new QListWidgetItem("Museums",myedit);
    eight->setCheckState(Qt::Unchecked);
    QListWidgetItem *nine= new QListWidgetItem("Art Galleries",myedit);
    nine->setCheckState(Qt::Unchecked);
    QListWidgetItem *ten= new QListWidgetItem("Cinemas",myedit);
    ten->setCheckState(Qt::Unchecked);
    QListWidgetItem *eleven= new QListWidgetItem("Theater",myedit);
    eleven->setCheckState(Qt::Unchecked);
    QListWidgetItem *twelve= new QListWidgetItem("Dance",myedit);
    twelve->setCheckState(Qt::Unchecked);
    QListWidgetItem *thirteen= new QListWidgetItem("Live Music",myedit);
    thirteen->setCheckState(Qt::Unchecked);
    QListWidgetItem *fourteen= new QListWidgetItem("Stores & Markets",myedit);
    fourteen->setCheckState(Qt::Unchecked);
    QListWidgetItem *fifteen= new QListWidgetItem("Food & Wine",myedit);
    fifteen->setCheckState(Qt::Unchecked);
    QListWidgetItem *sixteen= new QListWidgetItem("Clothing & Fashion",myedit);
    sixteen->setCheckState(Qt::Unchecked);
    QListWidgetItem *seventeen= new QListWidgetItem("Jewelry & Accessories",myedit);
    seventeen->setCheckState(Qt::Unchecked);
    QListWidgetItem *eighteen= new QListWidgetItem("Shoes",myedit);
    eighteen->setCheckState(Qt::Unchecked);
    QListWidgetItem *nineteen= new QListWidgetItem("Antiques",myedit);
    nineteen->setCheckState(Qt::Unchecked);
    QListWidgetItem *twenty= new QListWidgetItem("Bookshops",myedit);
    twenty->setCheckState(Qt::Unchecked);

    myedit->addItem(one);
    myedit->addItem(two);
    myedit->addItem(three);
    myedit->addItem(four);
    myedit->addItem(five);
    myedit->addItem(six);
    myedit->addItem(seven);
    myedit->addItem(eight);
    myedit->addItem(nine);
    myedit->addItem(ten);
    myedit->addItem(eleven);
    myedit->addItem(twelve);
    myedit->addItem(thirteen);
    myedit->addItem(fourteen);
    myedit->addItem(fifteen);
    myedit->addItem(sixteen);
    myedit->addItem(seventeen);
    myedit->addItem(eighteen);
    myedit->addItem(nineteen);
    myedit->addItem(twenty);


    QHBoxLayout *lay= new QHBoxLayout(mywidget);
    lay->addWidget(myedit);

    mywidget->setLayout(lay);

    mywidget->setGeometry(10,10,180,50);

    mywidget->show();

    return myapp.exec();

    }

  5. The following user says thank you to Seema Rao for this useful post:

    nielsenj (12th May 2006)

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Check Box problem

    Quote Originally Posted by Seema Rao
    the problem is items appear multiple times when I resize the window.
    Everything is OK on my system (Qt 4.1.2, PLD Linux).

  7. #6
    Join Date
    Jan 2006
    Location
    Cambridge, MA
    Posts
    32
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Check Box problem

    Seema,

    Remove the parents from your Item constructors or comment out the addIOtem calls. If you remove the parents the items should be automatically reparented by the addItem() call. I'm assuming by passing a listview parent the constructor is doing an implicit addItem on the parent.

  8. #7
    Join Date
    Sep 2007
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Check Box problem

    I want to do like this but I want only 1 checked item in the list ( right now I can check all of them at the same time) how I can do it ?

    Thank you

Similar Threads

  1. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  2. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  3. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  4. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.