Results 1 to 11 of 11

Thread: parsing QtableWidget from a QStackedWidget

  1. #1
    Join Date
    Aug 2006
    Posts
    7
    Thanks
    1

    Default parsing QtableWidget from a QStackedWidget

    Hi,

    I have a QStackedwidget that contains multiple QTableWidget. How can i parse all of the
    QTablewidget from the Qstackedwidget.

    example of my test, and the dynamic_cast is always false , is there a better way ?

    for (int i=0;i<stackedWidget->count() ; i++)
    {
    QWidget *poChild = stackedWidget->widget(i);
    if (poChild && dynamic_cast<QTableWidget*>(poChild) )
    {
    QTableWidget *poTBL = dynamic_cast<QTableWidget*>(poChild);
    poTBL->setColumnCount(0);
    poTBL->setRowCount(0);
    }
    }

    thanks,

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: parsing QtableWidget from a QStackedWidget

    You can use setObjectName() and objectName() to identify your tableWidgets.

  3. #3
    Join Date
    Aug 2006
    Posts
    7
    Thanks
    1

    Default Re: parsing QtableWidget from a QStackedWidget

    i want to make abstaction of the name, assume i don't know the name, there must be a way to iterate true children and cast them in the current type ?

    Thanks

  4. #4
    Join Date
    Aug 2006
    Posts
    7
    Thanks
    1

    Angry Re: parsing QtableWidget from a QStackedWidget

    maybee it's me that does not understand their architecture correclty . so if the method
    widget() returns me a qwidget, can i retreive the content of the widget, which i know are
    qTableWidget.


    for (int i=0;i<stackedWidget->count() ; i++)
    {
    QWidget *poChild = stackedWidget->widget(i); // this works

    }

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: parsing QtableWidget from a QStackedWidget

    How do you add the widgets to the stacked widget?
    J-P Nurmi

  6. #6
    Join Date
    Aug 2006
    Posts
    7
    Thanks
    1

    Default Re: parsing QtableWidget from a QStackedWidget

    i think it's because of the way it's displayed in the gui designer, If i look at the generated code

    stackedWidget = new QStackedWidget(centralwidget);
    stackedWidget->addWidget(page_0);
    page_1 = new QWidget();
    gridLayout2 = new QGridLayout(page_1);
    imageTBL = new QTableWidget(page_1);

    gridLayout2->addWidget(imageTBL, 0, 0, 1, 1);
    stackedWidget->addWidget(page_1);

    from that code how can i retreive the Qtable widget from the stackedWidget

    thanks,

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: parsing QtableWidget from a QStackedWidget

    Ok so the problem is that the widget being in the stack is not a QTableWidget. It's just a QWidget (page) which has a layout containing the table widget. But if you don't put any other widget into the layout, there is no point creating an additional wrapper widget and a layout.

    Qt Code:
    1. stackedWidget = new QStackedWidget(centralwidget);
    2. stackedWidget->addWidget(page_0);
    3. //page_1 = new QWidget();
    4. //gridLayout2 = new QGridLayout(page_1);
    5. imageTBL = new QTableWidget(stackedWidget);
    6.  
    7. //gridLayout2->addWidget(imageTBL, 0, 0, 1, 1);
    8. stackedWidget->addWidget(imageTBL);
    To copy to clipboard, switch view to plain text mode 

    EDIT: Errr.. ignore this. I don't know what did I have on my mind. Of course the table widget needs to be in a layout so that it's geometry gets managed at all.
    Last edited by jpn; 12th October 2006 at 17:12.
    J-P Nurmi

  8. #8
    Join Date
    Aug 2006
    Posts
    7
    Thanks
    1

    Default Re: parsing QtableWidget from a QStackedWidget

    the problem here is that this header code is generated by the QT code generator uic.bat and we need to keep it as is.

    i guess that there are no easy way to retreive the object in a loop

  9. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: parsing QtableWidget from a QStackedWidget

    Maybe it would be more flexible choice to use a QStackedLayout from code. You could insert the table widget directly to the stacked layout without using an additional wrapper widget for layouting like designer does..
    J-P Nurmi

  10. #10
    Join Date
    Feb 2006
    Location
    Boulder, Colorado, USA
    Posts
    63
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: parsing QtableWidget from a QStackedWidget

    have you tried using a qobject_cast?

  11. #11
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: parsing QtableWidget from a QStackedWidget

    Quote Originally Posted by jrideout View Post
    have you tried using a qobject_cast?
    This won't work because the widget returned by the stacked widget is not a QTableWidget. It's just a plain QWidget which has a layout containing the QTableWidget. QObject has methods for looking up children of specific type etc. These methods can be used to find the QTableWidget child.
    J-P Nurmi

  12. The following user says thank you to jpn for this useful post:

    rosmarcha (13th October 2006)

Similar Threads

  1. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 18:46
  2. QTableWidget Update - slow
    By DPinLV in forum Qt Programming
    Replies: 16
    Last Post: 18th August 2006, 21:09
  3. Replies: 6
    Last Post: 5th March 2006, 21:05
  4. Updating a QTableWidget through a Dialog
    By dragon in forum Newbie
    Replies: 3
    Last Post: 19th January 2006, 21:16
  5. How to obtain the width of a QTableWidget?
    By Giel Peters in forum Qt Programming
    Replies: 3
    Last Post: 9th January 2006, 22:34

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.