I'm use window qt, this is my code:
LaserEllipse::LaserEllipse(QWidget *parent):
.....
QLabel(parent),
_colore(new QColorDialog(this))
{
......
_colore->setCurrentColor(....);
// COSTRUZIONE MENU
_action_remove = new QAction("Remove Item" , this );
_action_color = new QAction("Change color" , this );
_contextMenu->addAction(_action_color);
_contextMenu->addAction(_action_remove);
connect(_action_remove, SIGNAL(triggered()), this, SLOT(action_remove()));
connect(_action_color, SIGNAL(triggered()), this, SLOT(action_color()));
_contextMenu->setStyleSheet("QMenu{background-color: rgba(255,255,255,255);selection-color: black;selection-background-color: rgba(162,217,247);}");
_colore->setStyleSheet("background-color: rgba(255,255,255,255);");
};
void LaserEllipse::action_color()
{
_colore->open(this, SLOT(aggiornaEllipse()));
}
void LaserEllipse::aggiornaEllipse()
{
_ellipse_t->setColor(_colore->currentColor().toRgb().name().toStdString());
_ellipse_t->setCX(this->geometry().center().x());
_ellipse_t->setCY(this->geometry().center().y());
_ellipse_t->setRX(this->width() / 2);
_ellipse_t->setRY(this->height() / 2);
}
In the last line, in action_color
slot function, appear QColorDialog
, but if I click "Ok" the button
keep pressed down and don't work, if I click "Cancel" nothing happens. To change color I must press enter.
What is wrong ?