Results 1 to 6 of 6

Thread: How to access Widgets created in Tab View

  1. #1
    Join Date
    Oct 2009
    Posts
    66
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default How to access Widgets created in Tab View

    Hi,
    I am new to Qt Environment, i am using a QTabWidget where i am adding eight tabs to it in a for loop. the elements present on each page of the tab are same.

    I am not able to get the control of widgets present on the 1st tab, can someone please help me on how can i get the control back on the tab one.
    Pasting the code snippet.

    Qt Code:
    1. tabWidget = new QTabWidget(parent);
    2. tabWidget->setGeometry(0,15,650,400);
    3. tabWidget->setStyleSheet("*{background-color:green;}");
    4.  
    5. for(int i=0; i<8;i++){
    6.  
    7. QString name(QString::number(1));
    8. tabWidget->addTab(myfunction(),tr("Profile").append(name));
    9. }
    10. connect(Modelcombo,SIGNAL(currentIndexChanged(int)),this,SLOT(stCurrentIndex(int)));
    11. connect(colorModecombo,SIGNAL(currentIndexChanged(int)),this,SLOT(stCurrentIndex(int)));
    12. }
    13.  
    14. /*The function is */
    15. QWidget* Widget::myfunction(){
    16.  
    17. page = new QWidget();
    18. page->setGeometry(0,25,650,500);
    19.  
    20. QLabel *Modelab = new QLabel(tr("Modle"),page);
    21. Modelab->setGeometry(0,60,120,20);
    22. Modelcombo = new QComboBox(page);
    23. ModelcombosetGeometry(200,60,100,20);
    24. Modelcombo->setFocusPolicy(Qt::NoFocus);
    25. Modelcombo->addItem(tr("Normal"));
    26. Modelcombo->addItem(tr("Bad"));
    27. Modelcombo->addItem(tr("Good"));
    28.  
    29. QLabel *colorModelab = new QLabel(tr("Color"),page);
    30. colorModelab->setGeometry(0,100,80,20);
    31. colorModecombo = new QComboBox(page);
    32. colorModecombo->setGeometry(200,100,100,20);
    33. colorModecombo->setFocusPolicy(Qt::NoFocus);
    34. colorModecombo->addItem(tr("Red"));
    35. colorModecombo->addItem(tr("Blue"));
    36. colorModecombo->addItem(tr("Green"));
    37.  
    38. return page;
    39. }
    40. /*the Slot is*/
    41. void Widget::stCurrentIndex(int val){
    42. qDebug()<< "Tab value is" << tabWidget->currentIndex();
    43. qDebug()<< "Modle mode is" << Modelcombo->currentText();
    44. qDebug()<< "Color is" << colorModecombo->currentText();
    45. }
    To copy to clipboard, switch view to plain text mode 

    As the content in each tab is the same when i try to connect to signal of combobox in tab 1, the signal is not emitted, but the signal is emitted for the last tab created. Please let me know hw to proceed from here as i want to extract the values of combobox of wach tab.
    Last edited by wysota; 23rd October 2009 at 00:32. Reason: missing [code] tags

  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: How to access Widgets created in Tab View

    What do you mean by "control"?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2009
    Posts
    66
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to access Widgets created in Tab View

    By "control" i mean, i am not able to get the value changed in the combobox of tab 0, if i try
    connect(Modelcombo,SIGNAL(currentIndexChanged(int) ),this,SLOT(stCurrentIndex(int)));
    connect(colorModecombo,SIGNAL(currentIndexChanged( int)),this,SLOT(stCurrentIndex(int)));

    the value shown in the slot is the value of combobox of tab7 and not tab 0, by some way i want the value of the combobox present in each tab individually.
    Is the way page created to add to the tab is correct, as all the tabs are having same widgets.

  4. #4
    Join Date
    Oct 2009
    Posts
    66
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Lightbulb Re: How to access Widgets created in Tab View

    This code certainly helped as what i was doing initially was incorrect

    Qt Code:
    1. for(int i=0; i<8;i++)
    2. {
    3. page[i] = new QWidget();
    4.  
    5. QLabel *recordingModelab[i] = new QLabel(tr("Recording Mode"),page[i]);
    6. recordingModelab[i]->setGeometry(0,60,120,20);
    7. recordingModecombo[i] = new QComboBox(page[i]);
    8. recordingModecombo[i]->setGeometry(200,60,100,20);
    9. recordingModecombo[i]->setFocusPolicy(Qt::NoFocus);
    10. recordingModecombo[i]->addItem(tr("Normal"));
    11. recordingModecombo[i]->addItem(tr("Bad"));
    12. recordingModecombo[i]->addItem(tr("Good"));
    13.  
    14. QLabel *resolutionModelab[i] = new QLabel(tr("Resolution"),page[i]);
    15. resolutionModelab[i]->setGeometry(0,100,80,20);
    16. resolutionModecombo[i] = new QComboBox(page[i]);
    17. resolutionModecombo[i]->setGeometry(200,100,100,20);
    18. resolutionModecombo[i]->setFocusPolicy(Qt::NoFocus);
    19. resolutionModecombo[i]->addItem(tr("CIF"));
    20. resolutionModecombo[i]->addItem(tr("D1"));
    21. resolutionModecombo[i]->addItem(tr("QCIF"));
    22.  
    23. QLabel *qualitylab[i] = new QLabel(tr("Bit Rate"),page[i]);
    24. qualitylab[i]->setGeometry(0,140,80,20);
    25. qualitycombo[i] = new QComboBox(page[i]);
    26. qualitycombo[i]->setGeometry(200,140,100,20);
    27. qualitycombo[i]->setFocusPolicy(Qt::NoFocus);
    28. qualitycombo[i]->addItem(tr("50 kbps"));
    29. qualitycombo[i]->addItem(tr("120 kbps"));
    30. qualitycombo[i]->addItem(tr("150 kbps"));
    31. qualitycombo[i]->addItem(tr("200 kbps"));
    32.  
    33.  
    34. QLabel *frameratelab[i] = new QLabel(tr("Frame Rate"),page[i]);
    35. frameratelab[i]->setGeometry(0,180,80,20);
    36. frameratecombo[i] = new QComboBox(page[i]);
    37. frameratecombo[i]->setGeometry(200,180,100,20);
    38. frameratecombo[i]->setFocusPolicy(Qt::NoFocus);
    39. frameratecombo[i]->addItem(tr("15 fps"));
    40. frameratecombo[i]->addItem(tr("25 fps"));
    41. frameratecombo[i]->addItem(tr("30 fps"));
    42.  
    43.  
    44. QString name(QString::number(1+i));
    45. tabWidget->addTab(page[i],tr("Profile").append(name));
    46.  
    47. }
    To copy to clipboard, switch view to plain text mode 


    If the same can be done in a better way, please share
    Last edited by wysota; 23rd October 2009 at 08:52. Reason: missing [code] tags

  5. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to access Widgets created in Tab View

    If all the tabs contain the same widgets (and they certainly seem to from your code), then you could create another ui file with your widgets, and then either:

    - subclass QWidget using Designers promotion feature and then use the same object for each tab (designer way)
    - create 8 copies of the object using 'new' and manually add the tabs using tabWidget->addTab

    Either way needs a lot less code than what you have.

  6. #6
    Join Date
    Oct 2009
    Posts
    66
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to access Widgets created in Tab View

    I tried creating 8 copies of the page object, but when i tried to access the values from the comboboxes on tab0, it gave the values of combobox 7 so i tried in this way.

Similar Threads

  1. how to access widgets values?
    By BalaQT in forum Qt Programming
    Replies: 4
    Last Post: 22nd August 2009, 12:06
  2. Replies: 6
    Last Post: 3rd September 2008, 14:27
  3. Access to widgets from a Dialog to another one
    By jean in forum Qt Programming
    Replies: 7
    Last Post: 7th August 2008, 09:42
  4. raised view of Widgets.
    By krishna.bv in forum Qt Programming
    Replies: 22
    Last Post: 25th January 2007, 11:21
  5. Access widgets
    By Gayathri in forum Newbie
    Replies: 2
    Last Post: 17th November 2006, 14:37

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.