Results 1 to 5 of 5

Thread: array of radio buttons

  1. #1
    Join Date
    Mar 2006
    Posts
    19
    Thanks
    1

    Question array of radio buttons

    hi there,

    i m trying to add an array of radio buttons in a grid layout and then further into a widget. but these radio buttons seem to overlap over each other. Thus in the output, there is only one radio button. Here is the code
    Qt Code:
    1. KPH_WIDGET::KPH_WIDGET(QWidget *parent, Qt::WFlags flags)
    2. : QMainWindow(parent, flags)
    3. {
    4. QPalette objPalette1;
    5. objPalette1.setColor(QPalette::Window,Qt::white);
    6. QPalette objPalette2;
    7. objPalette2.setColor(QPalette::Window,Qt::gray);
    8.  
    9. //setFixedSize(300,300);
    10. QGridLayout* pGridLayout = new QGridLayout(this);
    11.  
    12. CRadioButtonEx* arr[10] ;
    13. for(int i = 0; i < 10; i++)
    14. {
    15. pGridLayout->setRowMinimumHeight(i,50);
    16. arr[i] = new CRadioButtonEx(tr("check"),this);
    17.  
    18. if(arr[i])
    19. {
    20. if(i%2 == 0)
    21. arr[i]->setPalette(objPalette1);
    22. else
    23. arr[i]->setPalette(objPalette2);
    24.  
    25. arr[i]->setAutoFillBackground(true);
    26.  
    27.  
    28. }
    29.  
    30. pGridLayout->addWidget(arr[i],i,0,Qt::AlignLeft);
    31. }
    To copy to clipboard, switch view to plain text mode 

    Here, CRadioButtonEx is a customized radio button which works correctly. On debugging, it shows that all the 10 of the radio buttons are created. But only one is shown.

    Looking forward to a reply.

    Cheers,
    Amulya

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: array of radio buttons

    try arr[i]->show(); after/before adding to layout.

  3. #3
    Join Date
    Mar 2006
    Posts
    19
    Thanks
    1

    Default Re: array of radio buttons

    hi there,

    thanx for ur reply.
    it shows the same output i.e. only one radio button.
    i also tried to do it with normal QRadioButton..that also doesnt work

    any other suggestions??

    Amulya

  4. #4
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: array of radio buttons

    Hello ,
    You are trying to set your own layout in QMainWidget. Your are not supposed to do that.
    Instead you should create a widget and set it as central widget of QMainWindow. You can use your own layout in centralWidget.
    So try this code
    Qt Code:
    1. QPalette objPalette1;
    2. objPalette1.setColor(QPalette::Window,Qt::white);
    3. QPalette objPalette2;
    4. objPalette2.setColor(QPalette::Window,Qt::gray);
    5. //added these two lines and modified one line
    6. QWidget *centralWidget = new QWidget(this);
    7. setCentralWidget(centralWidget);
    8. QGridLayout* pGridLayout = new QGridLayout(centralWidget);
    9.  
    10. QRadioButton* arr[10] ;
    11. for(int i = 0; i < 10; i++)
    12. {
    13. pGridLayout->setRowMinimumHeight(i,50);
    14. arr[i] = new QRadioButton(tr("check"),this);
    15. if(arr[i])
    16. {
    17. if(i%2 == 0)
    18. arr[i]->setPalette(objPalette1);
    19. else
    20. arr[i]->setPalette(objPalette2);
    21. arr[i]->setAutoFillBackground(true);
    22. }
    23. pGridLayout->addWidget(arr[i],i,0,Qt::AlignLeft);
    24. }
    To copy to clipboard, switch view to plain text mode 
    Hope this helps !

  5. #5
    Join Date
    Mar 2006
    Posts
    19
    Thanks
    1

    Default Re: array of radio buttons

    hi gopala,

    i knew i was missing smth..anyways..u rock..problem solved

    thanx again

    Cheers,
    Amulya

Similar Threads

  1. widget for text AND buttons
    By nongentesimus in forum Newbie
    Replies: 2
    Last Post: 16th June 2006, 13:43
  2. How to create QPixmap from unsigned character array?
    By rashidbutt in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 18:25
  3. Paint XP radio button to pixmap
    By Ben.Hines in forum Qt Programming
    Replies: 2
    Last Post: 26th April 2006, 21:15
  4. How to get larger radio buttons on XP?
    By Ben.Hines in forum Qt Programming
    Replies: 9
    Last Post: 24th April 2006, 19:00
  5. QSettings again ... how to remove array elements
    By Mike in forum Qt Programming
    Replies: 4
    Last Post: 11th January 2006, 08:58

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.