Re: QTableWidget combobox
Take a look at the spinbox delegate example. Provide a combo box editor in the similar way than the example provides a spinbox.
Re: QTableWidget combobox
You dont keep combo boxes in your QTableWidget initially.
keep one combo boxe pointer seperatally as a member of class with hide.
whenever you click in any cell you do the following:
1. initialize your combo box with your data.
2. take data of that tableWidget's selected cell data and match with combo box data to make it selected in combobox
3. set combo box item in selected cell and show
4. after editing you read data of combo box and place in cell
5. hide your combo box.
Re: QTableWidget combobox
Dear jpn
For the spin box delegate doesnt help, because the data in the combo changes allways, but the other solution could help
Like the combos should be in the 2nd coloum. how we could send a signal for the second coloum?
Re: QTableWidget combobox
Quote:
Originally Posted by
aekilic
Like the combos should be in the 2nd coloum.
You can create combo box editors to 2nd column like this:
Code:
{
if (index.column() == 1)
{
// 2nd column is being edited, return a QComboBox as an editor
...
return editor;
}
}
Quote:
Originally Posted by
aekilic
For the spin box delegate doesnt help, because the data in the combo changes allways
Sure it does. setEditorData() gets always called for the item in question. Just fill the combo box accordingly:
Code:
void ComboBoxDelegate
::setEditorData(QWidget *editor,
{
if (index.column() == 1)
{
// 2nd column is being edited, we know it's a QComboBox
// fill the combo box with anything you want
QComboBox *comboBox
= static_cast<QComboBox
*>
(editor
);
comboBox->addItem(...);
...
}
else
{
}
}
Re: QTableWidget combobox
Dear Jpn
Could you please help us how we are going to put these into our code? Do we have to write a new cpp?
Re: QTableWidget combobox
Yes, I'd suggest implementing the delegate into separate files. Could you take a look at the spinbox delegate example as already suggested? Just create similar files for the delegate.
Re: QTableWidget combobox
we have made a new .h and a new .cpp
like
Code:
#ifndef TABLEIHALESARTNAMEDELEGATE_H
#define TABLEIHALESARTNAMEDELEGATE_H
#include <QItemDelegate>
#include <QModelIndex>
#include <QObject>
#include <QSize>
#include <QDoubleSpinBox>
#include <QtGui>
{
Q_OBJECT
public:
ComboBoxDelegate
(QObject *parent
= 0);
};
#endif
and made our .cpp
Code:
#include <QtGui>
#include "tableIhaleSartnameDelegate.h"
{
if (index.column() == 0)
{
// 2nd column is being edited, return a QComboBox as an editor
return editor;
}
}
after that what we should do?
Re: QTableWidget combobox
and how are are going to call for our delegate?
Re: QTableWidget combobox
Now you have to use it.
Code:
combo->setItemDelegate(new ComboBoxDelegate());
You could have seen how to use it if you just looked at the delegate examples.
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._ZN9formIhale1 9ihaleSartnameGosterEv+0x4d5): undefined reference to `ComboBoxDelegate::ComboBoxDelegate(QObject*)'
collect2: ld returned 1 exit status
make: *** [Deneme34d] Hata 1
Re: QTableWidget combobox
Quote:
Originally Posted by
aekilic
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._ZN9formIhale1 9ihaleSartnameGosterEv+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.
Re: QTableWidget combobox
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:
Code:
ComboBoxDelegate
::ComboBoxDelegate(QObject *parent
){
}
Re: QTableWidget combobox
Dear All
Thank you very much we have solved our problem. We were able to delegate the combobox!