Results 1 to 6 of 6

Thread: how to refer a dynamically added table widget inside a tab widget?

  1. #1
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default how to refer a dynamically added table widget inside a tab widget?

    Hi,
    I created a tab widget using designer,
    Then added table widget inside the tab widget...(one table in every tab)
    Now i want to access the values of a particular table, for example that table headers....
    How can i get that????

    And if there is multiple tabs,i want headers of presently activated tabs, tables header...
    Please guide me....

  2. #2
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to refer a dynamically added table widget inside a tab widget?

    Please somebody look at this issue...!!

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to refer a dynamically added table widget inside a tab widget?

    Hi,

    You can use a QList of QTableWidget pointers. The index of the current Tab will point to the QTableWidget.
    In the constructor of your application you can fillup the QList.
    Òscar Llarch i Galán

  4. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to refer a dynamically added table widget inside a tab widget?

    You should have pointer of you QTabWidget.
    Connect currentChanged( index ) signal from that widget to a slot that will do what you want when tab is changed.
    For example use QTabWidget::widget( index ) to get a current page widget and - if you don't have pointer to you table cached - iterate through its children looking for your table.

    Simpler may be to create a cache of table pointers indexed the same as pages they are on.

    Look at Qt Documentation for QTabWidget and all you need to know is there.

  5. #5
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to refer a dynamically added table widget inside a tab widget?

    i'm creating tab widget using designer...and then adding table widget inside the tab widget as shown below...
    Now how can i get access to table widget?

    Qt Code:
    1. void MainWindow::createFilesTable(int TagCount,QString FileName)
    2. {
    3.  
    4. filesTable = new QTableWidget(0,TagCount);
    5. filesTable->setSelectionBehavior(QAbstractItemView::SelectRows);
    6. filesTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
    7. filesTable->verticalHeader()->hide();
    8. ui->tabWidget->addTab(filesTable,FileName);
    9.  
    10. }
    To copy to clipboard, switch view to plain text mode 



    i tried like below to access the table i inserted inside the tab widget,,,,but compiler giving error..!
    Qt Code:
    1. void MainWindow::on_pushButton_FilterCollumn_clicked()
    2. {
    3.  
    4. QTableWidget *temp=ui->tabwidget->currentWidget();
    5.  
    6. }
    To copy to clipboard, switch view to plain text mode 
    its telling it cant convert 'QWidget' to 'QTableWidget'!!!
    Please tell me what changes i need to do?
    And also how can i get that table's header?


    Added after 50 minutes:


    hey i got it.....
    i did dynamic type conversion....
    Last edited by aurora; 14th December 2011 at 06:31.

  6. #6
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to refer a dynamically added table widget inside a tab widget?

    Hi,

    As I told you, you can use a QList of QTableWidget pointers like this:

    Qt Code:
    1. [LIST=1][*][COLOR=#0000ff]void[/COLOR] MainWindow[COLOR=#000000]::[/COLOR][COLOR=#009900]createFilesTable[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000ff]int[/COLOR] TagCount,[URL="http://doc.qt.nokia.com/latest/qstring.html"]QString[/URL] FileName[COLOR=#000000])[/COLOR]
    2. [*][COLOR=#000000]{[/COLOR]
    3. [*]
    4. [*] filesTable [COLOR=#000000]=[/COLOR] [COLOR=#009900]new[/COLOR] [URL="http://doc.qt.nokia.com/latest/qtablewidget.html"]QTableWidget[/URL][COLOR=#000000]([/COLOR][COLOR=#0000dd]0[/COLOR],TagCount[COLOR=#000000])[/COLOR];
    5. [*] filesTable[COLOR=#000000]-[/COLOR]>setSelectionBehavior[COLOR=#000000]([/COLOR][URL="http://doc.qt.nokia.com/latest/qabstractitemview.html"]QAbstractItemView[/URL][COLOR=#000000]::[/COLOR][COLOR=#009900]SelectRows[/COLOR][COLOR=#000000])[/COLOR];
    6. [*] filesTable[COLOR=#000000]-[/COLOR]>horizontalHeader[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]-[/COLOR]>setResizeMode[COLOR=#000000]([/COLOR][COLOR=#0000dd]0[/COLOR], [URL="http://doc.qt.nokia.com/latest/qheaderview.html"]QHeaderView[/URL][COLOR=#000000]::[/COLOR][COLOR=#009900]Stretch[/COLOR][COLOR=#000000])[/COLOR];
    7. [*] filesTable[COLOR=#000000]-[/COLOR]>verticalHeader[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]-[/COLOR]>hide[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
    8. [*] ui[COLOR=#000000]-[/COLOR]>tabWidget[COLOR=#000000]-[/COLOR]>addTab[COLOR=#000000]([/COLOR]filesTable,FileName[COLOR=#000000])[/COLOR];
    9. [*] tableList.append(filesTable); //Add the QTableWidget to the list
    10. [*][COLOR=#000000]}[/COLOR]
    11. [/LIST]
    To copy to clipboard, switch view to plain text mode 

    Then you can, as Spitfire told you, connect currentChanged( index ) signal to a slot and use index variable to obtain the QTableWidget pointer from the list:

    Qt Code:
    1. void MainWindow::tabIndexChanged(int index)
    2. {
    3. QTableWidget* tableWidget = tableList.at(index);
    4. ...
    5. }
    To copy to clipboard, switch view to plain text mode 

    Of course that you can use your method, but what happens if there is more than one widget into the tab? You have to search on the child widgets if there is one QTableWidget. but there will be another problem if there is more that one QTableWidget childs into the tab.
    Òscar Llarch i Galán

Similar Threads

  1. Qt Designer Size of table widget inside Tab Widget is not flexible.
    By akash in forum Qt Tools
    Replies: 2
    Last Post: 14th September 2011, 12:45
  2. Replies: 8
    Last Post: 28th June 2011, 15:57
  3. Replies: 0
    Last Post: 27th July 2010, 13:48
  4. Replies: 1
    Last Post: 14th November 2008, 03:59
  5. How to remove widget added in runtime?
    By jiveaxe in forum Qt Programming
    Replies: 7
    Last Post: 2nd November 2007, 11:13

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.