首页| 论坛| 消息

标题:为什么setForeground函数原型中形参类型为QBrush,而在上面例程中传入的参数类型为QColor也会编译动过?
作者:小白修炼中
日期:2016-04-29 17:48
内容:

函数原型:void QTextFormat::setForeground(const QBrush & brush)
QColor color = QColorDialog::getColor(Qt::black,this); //使用了标准颜色对话框的方式,当单击触发颜色按钮时,弹出标准颜色对话框选择颜色
if(color.isValid())
{
QTextCharFormat format;
format.setForeground(color);
showWidget->text->mergeCurrentCharFormat(format);
}
为什么setForeground函数原型中形参类型为QBrush,而在上面例程中传入的参数类型为QColor也会编译动过啊??求大神指导问题困扰了好久了,希望大神帮忙解决一下


#1 [kimtaikee 04-29 21:56]
这是C++基本功,编译器自动帮你用QColor创建了QBrush传给setForeground
QBrush(const QColor & color, Qt::BrushStyle style = Qt::SolidPattern)
QBrush(Qt::GlobalColor color, Qt::BrushStyle style = Qt::SolidPattern)

回复 发表
主题 版块