1 year ago
#344554
Qiang Zhang
How to add a QComboBox in QVTKOpenGLNativeWidget?
Now, I need to add a QComboBox in QVTKOpenGLNativeWidget. However, I find the signal-slot do not work.
The code is:
#include <qapplication.h>
#include <qsurfaceformat.h>
#include <QVTKOpenGLNativeWidget.h>
#include <qcombobox.h>
#include "qboxlayout.h"
class VTKTestWidget :public QVTKOpenGLNativeWidget
{
public:
VTKTestWidget()
{
m_combobox_ = new QComboBox;
m_combobox_->addItem("item1");
m_combobox_->addItem("item2");
QHBoxLayout* layout = new QHBoxLayout;
layout->addWidget(m_combobox_);
this->setLayout(layout);
connect(m_combobox_, SIGNAL(currentIndexChanged), this, SLOT(widgetComboboxIndexChangeSlot));
}
public slots:
void widgetComboboxIndexChangeSlot(int index)
{
std::cout << index << std::endl;
}
protected:
QComboBox* m_combobox_;
};
int main(int argc, char* argv[])
{
QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat());
QApplication a(argc, argv);
VTKTestWidget* widget = new VTKTestWidget;
widget->show();
return a.exec();
}
When I change the index of QComboBox, the widgetComboboxIndexChangeSlot would not be called.
How can I fix this problem? Or the QVTKOpenGLNativeWidget can not be treated as a normal QWidget?
Any suggestion is appreciated~~~~
------------------------- Update -------------------------------- Finally, thanks to @drescherjm, this problem is solved by:
connect(m_combobox_, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetComboboxIndexChangeSlot(int)));
c++
qt
vtk
0 Answers
Your Answer