Results 1 to 20 of 54

Thread: QTableWidget problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    111
    Thanked 4 Times in 4 Posts

    Red face Re: QTableWidget problem

    Quote Originally Posted by wysota View Post
    If you don't feel confident in creating your own model, use QStandardItemModel and reimplement QStandardItem by adding your structure to it. I think the docs explain how to do this.
    I've been searching docs and two books regarind adding custom structore to QStandardItem, however, I did not find it. I do not know how to continue, please help ... Does anyone has example?
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTableWidget problem

    QStandardItem docs, section "Subclassing".

  3. The following user says thank you to wysota for this useful post:

    MarkoSan (11th April 2008)

  4. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    111
    Thanked 4 Times in 4 Posts

    Red face Re: QTableWidget problem

    I've read it, wysota, but I still do not know how to integrate my struct into subclassed QStandardItem. Here is what I've done so far (it is very little), I really would need some deeper help. The header:
    Qt Code:
    1. #ifndef CSHOPPINGCARTITEM_H_
    2. #define CSHOPPINGCARTITEM_H_
    3.  
    4. // qt includes
    5. #include <QStandardItem>
    6.  
    7. static const int STRUCT_ORDER_TYPE=1001;
    8.  
    9. class CShoppingCartItem : public QStandardItem
    10. {
    11. public:
    12. CShoppingCartItem(QObject* parent=0);
    13.  
    14. int type() const;
    15. };
    16.  
    17. #endif /*CSHOPPINGCARTITEM_H_*/
    To copy to clipboard, switch view to plain text mode 
    Implementation:
    Qt Code:
    1. #include "CShoppingCartItem.h"
    2.  
    3. CShoppingCartItem::CShoppingCartItem(QObject* parent)
    4. {
    5. }
    6.  
    7. int CShoppingCartItem::type() const
    8. {
    9. return STRUCT_ORDER_TYPE;
    10. }
    To copy to clipboard, switch view to plain text mode 
    Where do I put my struct?!
    Qt 5.3 Opensource & Creator 3.1.2

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTableWidget problem

    Either as a member variable or as a superclass. Either way you'll have to reimplement other methods mentioned in the docs if you want to use the structure for anything. But before you do, think if you do need the structure at all. You might use QStandardItem without subclassing - just use custom roles and set your data.

  6. #5
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    111
    Thanked 4 Times in 4 Posts

    Default Re: QTableWidget problem

    How do I use custom roles? I've been reading docs but I still do not see the way how to do this task.
    Qt 5.3 Opensource & Creator 3.1.2

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTableWidget problem

    Role is simply a number. Just use setData() and data() with a number of your choice but not less than Qt::UserRole. I think the docs are quite clear about it. You can also take a look at the wiki article about [wiki=QAbstractItemModel]models[/wiki].

  8. #7
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    111
    Thanked 4 Times in 4 Posts

    Default Re: QTableWidget problem

    Well, I've reimplemented QAbstractTableModel and QTableView, it works ok. The last step is to reimplement QStandardItem for delegate get to work. But right now I am confused regarding layouts. In the attachemnt there is a GUI of my application module. Well, widgets named "QPUSHBUTTON1" and "QTABLEVIEW" are connected via QVBoxLayout. This vertical layout resided with main operation's window (wich is also vertical layouted with 3 pushbuttons placed under it - the 3 pushbuttons are horiz. layouted) vertical layout in horizontal layout. Now, the layout of QPUSHBUTTON1 and QTABLEVIEW is too wide. Now, how can I make main operation window wider and QPUSHBUTTON1 with QTABLEVIEW narrower. Do I have to begin experiment with layouts or the widgets inside "actor" layouts?
    Attached Images Attached Images
    Qt 5.3 Opensource & Creator 3.1.2

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTableWidget problem

    You can adjust horizontal stretches and/or size policies of widgets.

  10. #9
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    111
    Thanked 4 Times in 4 Posts

    Default Re: QTableWidget problem

    Well, I used resize function, but there are no results ...
    Qt 5.3 Opensource & Creator 3.1.2

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTableWidget problem

    Resize won't work as layouts override it. Use what I suggested.

  12. #11
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    111
    Thanked 4 Times in 4 Posts

    Default Re: QTableWidget problem

    well, if I knew what you thought I would not be asking now ... Will go now read docs, thanks for hints and tips, wysota...
    Qt 5.3 Opensource & Creator 3.1.2

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTableWidget problem

    I told you the names of fields in Designer. I think I can expect someone with at least two years of experience to locate them there.

Similar Threads

  1. Replies: 3
    Last Post: 11th August 2007, 11:00
  2. experiencing problem at printing out QTableWidget
    By rmagro in forum Qt Programming
    Replies: 9
    Last Post: 27th June 2007, 17:04
  3. QTableWidget Problem, setRowWidget? :P
    By VireX in forum Newbie
    Replies: 17
    Last Post: 6th April 2007, 19:12
  4. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 19:46
  5. Problem inserting in QTableWidget
    By DPinLV in forum Qt Programming
    Replies: 2
    Last Post: 2nd August 2006, 01:10

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
  •  
Qt is a trademark of The Qt Company.