我正在使用 Qt5 构建一个 C++ 应用程序。在QPen的例子中我看到我可以设置画笔如下:
QPen* myPen = new QPen();
myPen->setBrush(Qt::cyan);
虽然编译正常,但与文档不符。 QPen 的 setBrush 方法应该接收 QBrush。为什么传入 Qt::GlobalColor 是可以接受的?从 QPen.h 文件来看,setBrush 似乎没有过载。
最佳答案
QBrush
有一个用于Qt::GlobalColor
的转换构造函数,即编译器可以使用它来将Qt::GlobarColor
转换为QBrush
.
这是它在qbrush.h
中的定义:
QBrush(Qt::GlobalColor color, Qt::BrushStyle style = Qt::SolidPattern)
这个构造函数是在你的 myPen->setBrush(Qt::cyan);
函数调用中调用的,为你创建一个 QBrush
并传递给 setBrush()
.
检查 this了解有关转换构造函数概念的更多信息。
关于c++ - qpen 的 setbrush 方法参数与文档不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34540602/