我正在使用鼠标点击绘制一条线.使用绘图函数绘制线条:
painter->drawLine(start_p, end_p);
Run Code Online (Sandbox Code Playgroud)
线的边界矩形定义为:
QRectF Line::boundingRect() const
{
// bounding rectangle for line
return QRectF(start_p, end_p).normalized();
}
Run Code Online (Sandbox Code Playgroud)

这显示了画线.我得到了这个的边界矩形如图所示:

我希望根据项目的形状来设置边界矩形,例如:
怎么做到这一点?
编辑
在选择任何重叠线条时,选择顶部带有边界矩形的线条(参见下图).即使使用setZValue也不会在这里工作.我想通过最小化线条形状的边界矩形来实现这一点.

我QPainterPath在两点之间画一条线如下:
QPainterPath line;
line.moveTo(start_p);
line.lineTo(end_p);
QPen paintpen(Qt::black);
paintpen.setWidth(1);
painter->setRenderHint(QPainter::Antialiasing);
painter->setBrush(Qt::SolidPattern);
painter->setPen(paintpen);
painter->drawPath(line);
Run Code Online (Sandbox Code Playgroud)
我已将bounding rect定义为:
QRectF Line::boundingRect() const
{
return QRectF(start_p.x(), start_p.y(), end_p.x(), end_p.y());
}
Run Code Online (Sandbox Code Playgroud)
我在以下情况下正确画线:
start_p.x() < end_p.x()
Run Code Online (Sandbox Code Playgroud)
和
start_p.y() < end_p.y()
Run Code Online (Sandbox Code Playgroud)
如何定义边界矩形,以便无论两点坐标(start_p和end_p)之间的关系如何都能正确绘制直线?
我在Qt Creator的设计模式中设置了工具按钮的工具提示持续时间.该应用程序在Qt Creator中运行得很好.
但是当我使用make然后使用qmake命令在终端命令中运行相同的应用程序时,我得到了与我在设计器模式中添加的每个工具按钮相关的以下错误:
ui_mainwindow.h:377:22: error: ‘class QToolButton’ has no member named ‘setToolTipDuration’ pointButton->setToolTipDuration(200000);
Run Code Online (Sandbox Code Playgroud)
使用make命令时为什么会显示上述错误?如何使用make命令?
我正在cmake ../../ogre_src_v1-8-1我的build目录中使用构建 OGRE 源代码。我调查了许多类似的错误,但没有任何结果对我有用。
上面提到的 cmake 命令的输出给出了以下输出:
-- Configuring OGRE 1.8.1
-- Detected g++ 4.8
-- Enabling GCC visibility flags
-- Search path: /home/kamal/Documents/ogre_src_v1-8-1/build/Dependencies;/home/kamal/Documents/ogre_src_v1-8-1/Dependencies;/home/kamal/Documents/ogre_src_v1-8-1/build/../Dependencies;/home/kamal/Documents/ogre_src_v1-8-1/../Dependencies
-- Looking for ZLIB...
-- Found ZLIB: optimized;/usr/lib/x86_64-linux-gnu/libz.so;debug;/usr/lib/x86_64-linux-gnu/libz.so
-- Looking for ZZip...
-- Found ZZip: optimized;/usr/lib/x86_64-linux-gnu/libzzip.so;debug;/usr/lib/x86_64-linux-gnu/libzzip.so
-- Looking for FreeImage...
-- checking for module 'freeimage'
-- package 'freeimage' not found
-- Found FreeImage: optimized;/usr/lib/libfreeimage.so;debug;/usr/lib/libfreeimage.so
-- Looking for FREETYPE...
-- CMAKE_PREFIX_PATH: /home/kamal/Documents/ogre_src_v1-8-1/build/Dependencies;/home/kamal/Documents/ogre_src_v1-8-1/Dependencies;/home/kamal/Documents/ogre_src_v1-8-1/build/../Dependencies;/home/kamal/Documents/ogre_src_v1-8-1/../Dependencies;/usr/local;/usr/lib/x86_64-linux-gnu
-- CMAKE_PREFIX_PATH: /home/kamal/Documents/ogre_src_v1-8-1/build/Dependencies;/home/kamal/Documents/ogre_src_v1-8-1/Dependencies;/home/kamal/Documents/ogre_src_v1-8-1/build/../Dependencies;/home/kamal/Documents/ogre_src_v1-8-1/../Dependencies;/usr/local;/usr/lib/x86_64-linux-gnu
-- Could not locate FREETYPE
-- Looking for …Run Code Online (Sandbox Code Playgroud)