Unsolved The parent Dialog gets closed when I click ok to QColorDialog
-
I have following code that is using https://github.com/liangqi/qt-solutions/tree/master/qtcolorcombobox/srcand the code for QtColorComboBox is taken from https://github.com/liangqi/qt-solutions/tree/master/qtcolorcombobox/src
In this case I have Custom Dialog which is using QtColorComboBox . In code of QtColorComboBox there is open More..and clicking on More will be open a QColorDialog and when I click on any color and the press OK of QColorDialog then my parent dialog with title Color Dialog gets closed
Can some one tell me the fix for this issue
// set the dialog title
setWindowTitle("Color Dialog");
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);QLabel* nameLabel = new IN_CURRENT_POOL QLabel(tr("Color:"));
colorCB = new IN_CURRENT_POOL QtColorComboBox(this);
colorCB->setColorDialogEnabled(true);
colorCB->setStandardColors();
colorCB->setCurrentColor(Qt::blue);
nameLabel->setBuddy(colorCB);setButton = new IN_CURRENT_POOL QPushButton("Set", this);
closeButton = new IN_CURRENT_POOL QPushButton("Close", this);
setButton->setMaximumWidth(90);
closeButton->setMaximumWidth(90);QGridLayout *gridLayout = new IN_CURRENT_POOL QGridLayout;
QHBoxLayout * firstHboxLayout = new IN_CURRENT_POOL QHBoxLayout;
QHBoxLayout * secondHboxLayout = new IN_CURRENT_POOL QHBoxLayout;
firstHboxLayout->addWidget(nameLabel);
firstHboxLayout->addWidget(colorCB);
secondHboxLayout->addWidget(setButton);
secondHboxLayout->addWidget(closeButton);
gridLayout->addLayout(firstHboxLayout,0,0);
gridLayout->addLayout(secondHboxLayout,1,0);
setLayout(gridLayout);// QT connections
connect(setButton, SIGNAL(clicked()), this, SLOT(setColor()));
connect(closeButton, SIGNAL(clicked()), this, SLOT(hide()) -
CustomColorDialog::CustomColorDialog(QWidget* parent)
:QDialog(parent),d_colorCB(0),d_setButton(0),d_closeButton(0)
{
// set the dialog title
setWindowTitle("Set Color");
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);QLabel* nameLabel = new QLabel(tr("Color:"));
d_colorCB = new QtColorComboBox(this);
d_colorCB->setColorDialogEnabled(false);
d_colorCB->setStandardColors();
d_colorCB->setCurrentColor(Qt::blue);
nameLabel->setBuddy(d_colorCB);d_setButton = new QPushButton("Set", this);
d_closeButton = new QPushButton("Close", this);
d_setButton->setMaximumWidth(90);
d_closeButton->setMaximumWidth(90);QGridLayout *gridLayout = new QGridLayout;
QHBoxLayout * firstHboxLayout = new QHBoxLayout;
QHBoxLayout * secondHboxLayout = new QHBoxLayout;
firstHboxLayout->addWidget(nameLabel);
firstHboxLayout->addWidget(d_colorCB);
secondHboxLayout->addWidget(d_setButton);
secondHboxLayout->addWidget(d_closeButton);
gridLayout->addLayout(firstHboxLayout,0,0);
gridLayout->addLayout(secondHboxLayout,1,0);
setLayout(gridLayout);// QT connections
connect(d_setButton, SIGNAL(clicked()), this, SLOT(setColor()));
connect(d_closeButton, SIGNAL(clicked()), this, SLOT(hide()));}
The parent dialog is QDialog . can some one help me
class GQCustomColorDialog: public QDialog
{
Q_OBJECT
public:
GQCustomColorDialog(QWidget* parent = NULL);
~GQCustomColorDialog();
public slots:
virtual void setColor() =0;
protected:
QtColorComboBox* d_colorCB;
QPushButton* d_setButton;
QPushButton* d_closeButton;
}; -
please also show HOW you open the dialog in mainwinodw
-
GQSetColorDialogForInstView* d_setColorDialog ;
void myView::setColor()
{if (d_setColorDialog == NULL) { d_setColorDialog = new GQSetColorDialogForInstView(this); } d_setColorDialog->raise(); d_setColorDialog->show();
}
}GQSetColorDialogForInstView::GQSetColorDialogForInstView( QWidget* parent)
:GQCustomColorDialog(parent),d_inst(0),d_instView(sourceView),d_phyView(destView)
{
} -
Hmm, nothing spring to mind why it should close mainwindow
Do you get any kind of message in creator console?