Results 1 to 15 of 15

Thread: QTableWidget combobox

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2007
    Posts
    201
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    22

    Default Re: QTableWidget combobox

    we have made a new .h and a new .cpp

    like
    Qt Code:
    1. #ifndef TABLEIHALESARTNAMEDELEGATE_H
    2. #define TABLEIHALESARTNAMEDELEGATE_H
    3.  
    4. #include <QItemDelegate>
    5. #include <QModelIndex>
    6. #include <QObject>
    7. #include <QSize>
    8. #include <QDoubleSpinBox>
    9. #include <QtGui>
    10.  
    11.  
    12. class ComboBoxDelegate : public QItemDelegate
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. ComboBoxDelegate(QObject *parent = 0);
    18.  
    19. QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
    20. const QModelIndex &index) const;
    21. };
    22.  
    23. #endif
    To copy to clipboard, switch view to plain text mode 

    and made our .cpp

    Qt Code:
    1. #include <QtGui>
    2. #include "tableIhaleSartnameDelegate.h"
    3.  
    4. QWidget *ComboBoxDelegate::createEditor(QWidget *parent,
    5. const QStyleOptionViewItem &option,
    6. const QModelIndex &index) const
    7. {
    8. if (index.column() == 0)
    9. {
    10. // 2nd column is being edited, return a QComboBox as an editor
    11. QComboBox *editor = new QComboBox(parent);
    12.  
    13. return editor;
    14. }
    15. return QItemDelegate::createEditor(parent, option, index);
    16. }
    To copy to clipboard, switch view to plain text mode 

    after that what we should do?

  2. #2
    Join Date
    Jan 2007
    Posts
    201
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    22

    Default Re: QTableWidget combobox

    and how are are going to call for our delegate?

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: QTableWidget combobox

    Now you have to use it.
    Qt Code:
    1. QComboBox *combo = new QComboBox();
    2. combo->setItemDelegate(new ComboBoxDelegate());
    To copy to clipboard, switch view to plain text mode 


    You could have seen how to use it if you just looked at the delegate examples.

  4. The following user says thank you to marcel for this useful post:

    aekilic (14th September 2007)

  5. #4
    Join Date
    Jan 2007
    Posts
    201
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    22

    Default Re: QTableWidget combobox

    I have tried that but we have an error like

    QtCore -lz -lm -lrt -ldl -lpthread
    obj/moc_anaPencere.o: In function `formIhale::ihaleSartnameGoster()':
    moc_anaPencere.cpp.gnu.linkonce.t._ZN9formIhale19ihaleSartnameGoster Ev+0x4d5): undefined reference to `ComboBoxDelegate::ComboBoxDelegate(QObject*)'
    collect2: ld returned 1 exit status
    make: *** [Deneme34d] Hata 1

  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: QTableWidget combobox

    Quote Originally Posted by aekilic View Post
    I have tried that but we have an error like

    QtCore -lz -lm -lrt -ldl -lpthread
    obj/moc_anaPencere.o: In function `formIhale::ihaleSartnameGoster()':
    moc_anaPencere.cpp.gnu.linkonce.t._ZN9formIhale19ihaleSartnameGoster Ev+0x4d5): undefined reference to `ComboBoxDelegate::ComboBoxDelegate(QObject*)'
    collect2: ld returned 1 exit status
    make: *** [Deneme34d] Hata 1
    Implementation body is missing. In another words, there's a declaration but no implementation for ComboBoxDelegate constructor.
    J-P Nurmi

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

    aekilic (17th September 2007)

  8. #6
    Join Date
    Jan 2007
    Posts
    201
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    22

    Default Re: QTableWidget combobox

    What should we do?

  9. #7
    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: QTableWidget combobox

    Plain declaration of a function is not enough. To be able to use a function you must also implement it. So add an implementation for ComboBoxDelegate constructor to your .cpp file:
    Qt Code:
    1. ComboBoxDelegate::ComboBoxDelegate(QObject *parent)
    2. QItemDelegate(parent)
    3. {
    4. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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

    aekilic (17th September 2007)

  11. #8
    Join Date
    Jan 2007
    Posts
    201
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    22

    Default Re: QTableWidget combobox

    Dear All

    Thank you very much we have solved our problem. We were able to delegate the combobox!

Similar Threads

  1. Qtablewidget Combobox
    By aekilic in forum Qt Programming
    Replies: 17
    Last Post: 7th July 2015, 11:22
  2. QTableWidget issues
    By Djony in forum Qt Programming
    Replies: 42
    Last Post: 19th December 2006, 23:27
  3. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 18:46
  4. Filling combobox from database
    By Philip_Anselmo in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2006, 17:53
  5. Replies: 6
    Last Post: 5th March 2006, 21:05

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.