QColorDialog dialog(this); //这里使用this->goemetry().y()是因为如果使用this->y()将是不包含标题栏的y坐标,会导致setGeometry后,有可能标题栏超出屏幕外 dialog.setGeometry(this->geometry().x(), this->geometry().y(), dialog.width(), dialog.height()); dialog.setWindowTitle(tr("请设置字体颜色")); dialog.setCurrentColor(QColor(0, 0, 0)); //设置打开后的默认颜色 if(dialog.exec() == QColorDialog::Accepted) { QColor getColor = dialog.selectedColor(); //获取到的颜色 }