我使用的是窗口qt,这是我的代码:
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);
}
在最后一行,在action_color
插槽功能中,显示QColorDialog
,但如果我点击“确定”按钮
如果我点击“取消”没有任何反应,请保持按下并且不起作用。要改变颜色,我必须按回车。
有什么问题?