Results 1 to 9 of 9

Thread: Delegates and Table

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    16
    Thanked 2 Times in 2 Posts

    Default Re: Delegates and Table

    Quote Originally Posted by jpn
    You can only set one item delegate per view. That particular item delegate may create different type of editors for different model indexes, though.
    does different editors means the same thing that i need, i.e., combo in one column and spinbox in other ?

    how can i set editor for different inedxes ?

    can't the different delegate be used for different columns ?
    Do what u r afraid to do, and the death of fear is sure.

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

    Default Re: Delegates and Table

    Quote Originally Posted by ankurjain
    does different editors means the same thing that i need, i.e., combo in one column and spinbox in other ? how can i set editor for different inedxes ?
    Create a combo or spin box according to the model index column. Something like:
    Qt Code:
    1. QWidget* SpinBoxDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
    2. {
    3. if (index.column() == something)
    4. {
    5. QSpinBox* editor = new QSpinBox(parent);
    6. ...
    7. return editor;
    8. }
    9. else
    10. {
    11. QComboBox* editor = new QComboBox(parent);
    12. ...
    13. return editor;
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    Just be aware that then you need to check which column is in question and cast to appropriate widget in setEditorData() and setModelData()...

    can't the different delegate be used for different columns ?
    Unfortunately nope. A single item delegate can be set for the whole view and it's model.
    J-P Nurmi

  3. The following 3 users say thank you to jpn for this useful post:

    ankurjain (25th April 2006), gfunk (18th May 2006), Jimmy2775 (30th May 2006)

  4. #3
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    16
    Thanked 2 Times in 2 Posts

    Default Re: Delegates and Table

    thanks JPN Brother ....

    hey can u tell me how can i make myself conceptually more clear for qt. i find the tuts ( the desrciption ) somewhat insufficient ( not totally targeted towards brginners ).

    ne resources ??
    Do what u r afraid to do, and the death of fear is sure.

  5. #4
    Join Date
    May 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Delegates and Table

    Hi All,
    This is my first post, by the way, I salute everyone.

    I don't know QT very much, i'm just started few weeks ago.
    Is there any way to achieve that trick by using QTableWidget / QTableWidgetItem ?
    I read a tutorial about a QT3 QTable / QTableItem where it's seems to be achievable!

    Use of QTableWidget::addItem ( int row, int column, QTableWidgetItem * qtwItem ) could be useful?
    Last edited by KekraU; 17th May 2006 at 23:17.

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

    Default Re: Delegates and Table

    Quote Originally Posted by KekraU
    Is there any way to achieve that trick by using QTableWidget / QTableWidgetItem ?
    If you are looking for different kinds of editors, you can use a custom item delegate with QTableWidget as well. Just be aware that the "default item delegate" QItemDelegate already offers through the QItemEditorFactory a few different editor widgets for different types of data:
    - QComboBox for booleans
    - QSpinBox for integers (both signed and unsigned)
    - QDoubleSpinBox for doubles
    - QDateTimeEdit for datetimes
    - QDateEdit for dates
    - QTimeEdit for times
    (- QLabel for pixmaps)
    - QLineEdit otherwise

    A common mistake is to insert all data as text. By this way you'll end up always having a QLineEdit as the editor. You can use the method QTableWidgetItem::setData() to set different kinds of data for an item.

    If you just want to place some widgets persistently in the cells, you may use cell widgets.
    J-P Nurmi

  7. #6
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    16
    Thanked 2 Times in 2 Posts

    Default Re: Delegates and Table

    Quote Originally Posted by KekraU
    Use of QTableWidget::addItem ( int row, int column, QTableWidgetItem * qtwItem ) could be useful?
    hi kekrau,
    i m using qt-4.1.2 but i can't find the function that u mentioned in qtablewidget.

    Thanx jpn for giving idea to use cellWidget
    Last edited by ankurjain; 18th May 2006 at 07:34.
    Do what u r afraid to do, and the death of fear is sure.

  8. #7
    Join Date
    May 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Delegates and Table

    Thxs JPN.
    I have already looked at these Editors...
    I think the main point with these Editors (you mentionned) that they could be use outside TableView... to edit these kind of data (Time, Date, DateTime, Integer, and so on...) in QTableView/QTableWidget you have to include in your class which inherite from QItemDelegate, these editors.

    And in fact, that is what I did to solve my problem... include Q[Editor] (ComboBox / SpinBox...) in my cell depending on the type I want to edit.
    Plus, i used QTableWidget to setBackGroundColor... Really funny SpinBox on Red Background

    @Ankurjain:
    In fact, I search on the website, and I did not find QTableWidget::addItem, but on my 4.1.0 I have it.... But you got QTableWidget::setItem( int row, int column, QTableWidgetItem * item ) which has the same prototype and seems to do the same as previous addItem

    Your link
    Last edited by KekraU; 18th May 2006 at 19:51.

Similar Threads

  1. Table Widget Vs. Table View
    By winston2020 in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2008, 09:56
  2. Easiest way to display icons in a table
    By ghorwin in forum Qt Programming
    Replies: 3
    Last Post: 19th March 2007, 13:09
  3. Setting Delegates per Column
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 30th May 2006, 21:39

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.