为什么将宽度设置为其他1会使我的行消失
Why setwidth to other then 1 makes my line disappear?
正如我的代码片段allready中的注释所解释的:
对于笔宽度为的笔设置为noneSelectedLine
的行,代码无法按预期工作!=1.
scene = new QGraphicsScene();
Qt::PenStyle ePenStyl = Qt::DashLine;
selectedLine = new QPen(Qt::blue);
noneSelectedLine = new QPen(Qt::red);
selectedLine->setWidth(2);
noneSelectedLine->setWidth(1);
noneSelectedLine->setDashPattern(QVector<qreal>(ePenStyl));
/*If this line is a comment all is running as expected, but as soon as I
set in the following line, all lines where the pen is set to
noneSelectedLine they are not drawn (or at least not visible). What could
be the reason for that?*/
//noneSelectedLine->setWidth(3);
for (int indexI = 0; indexI < 5; indexI++)
{
scene->addItem(&LineSet[indexI]);
}
这里会有什么原因?如果片段中缺少一些信息,请告诉我,我会澄清的。
您的代码存在多个问题。首先,向量构造函数QVector<qreal>(something)
的这种重载创建了一个qreal
的向量,其大小为something
个元素,每个元素都将用默认值初始化。
其次,Qt::DashLine
是解析为2
的enum
值,因此线QVector<qreal>(ePenStyl)
创建2个qreal
s的向量,其值将为0。
第三,setDashPattern
并不像你想象的那样工作。这是来自医生的一句话:
将此笔的划线图案设置为给定的图案。这会将笔的样式隐式转换为Qt::CustomDashLine。
模式必须指定为偶数个正条目,其中条目1、3、5…是短划线,条目2、4、6…是空格。
我想你想做的是
noneSelectedLine->setStyle( ePenStyl );
而不是
noneSelectedLine->setDashPattern(QVector<qreal>(ePenStyl));
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 我的字符计数代码计算错误.为什么
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- cmake在我的项目中所需的所有静态库都不成功
- 为什么我的代码在输出中增加了93天
- 我的简单if-else语句是如何无法访问的代码
- 为什么我的for循环不能正确获取argv
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 为什么在我释放左键单击后,我的绘图会消失
- 为什么当我写入文件时,结构在我的文件中消失了
- 为什么使用程序会导致我的形状消失?
- 我的地板平面的一部分消失了
- 当我添加OpenGL转换时,我的图像不断消失
- 为什么我的 cmd 消失了?我使用 cin.ignore(),但它没有效果!C++
- 我的 SDL 应用程序的窗口弹出并立即消失
- 为什么将宽度设置为其他1会使我的行消失
- 为什么当我在OpenGL中启用照明时,我的颜色消失了?
- 当从c++传递缓冲区到NodeJS时,我的数据消失了
- C++当我离开默认构造函数时,我的初始化字符串消失了,但我的其他成员变量值没有