学说查询不同的相关实体(Doctrine query distinct related entity)
我可能忽略了一些非常简单的东西,只是盯着它太多,但我无法让这个DQL查询工作。 我收到一个异常,指出:
Cannot select entity through identification variables without choosing at least one root entity alias.
这是我的查询。 用户与Group有多对一的关系。 请注意,这是一种单向关系! 这对你来说可能没有意义,但在我们的领域逻辑中它是有意义的。
SELECT DISTINCT g FROM Entity\User u LEFT JOIN u.group g WHERE u.active = :active
你能告诉我我在这里错过了什么吗?
I'm probably overlooking something very simple and just been staring at it too much, but I can't get this DQL query to work. I get an exception stating:
Cannot select entity through identification variables without choosing at least one root entity alias.
Here's my query. User has a many-to-one relation to Group. Note that this is a unidirectional relation! That may make no sense to you, but it makes sense in our domain logic.
SELECT DISTINCT g FROM Entity\User u LEFT JOIN u.group g WHERE u.active = :active
Can you tell me what I am missing here?
原文:https://stackoverflow.com/questions/10204700
最满意答案
在哪里实例化QPen并不重要。
QPen的默认宽度为0.这是一个特殊的值,这意味着化妆品是真实的,宽度实际上是1.所以,如果你不想让笔化妆,你必须将其设置为所需的宽度。 您可能还需要将化妆品设置为假。
这是一个简单的例子:
#include <QtGui> int main(int argc, char *argv[]) { QApplication a(argc, argv); QGraphicsView view; QGraphicsScene scene; QGraphicsRectItem *item1 = scene.addRect(20, 20, 20, 20); QGraphicsRectItem *item2 = scene.addRect(50, 20, 20, 20); QPen pen1, pen2; pen1.setWidth(5); pen2.setWidth(5); pen1.setCosmetic(true); pen2.setCosmetic(false); item1->setPen(pen1); item2->setPen(pen2); view.setScene(&scene); view.scale(4, 4); // both rects are the same size, but one a has wider pen view.show(); return a.exec(); }
It doesn't really matter where you instantiate the QPen.
QPen has a default width of 0. This is a special value that means cosmetic is true and the width is actually 1. So if you don't want the pen to be cosmetic you have to set it to the desired width. You might also need to set cosmetic to false.
Here is a simple example:
#include <QtGui> int main(int argc, char *argv[]) { QApplication a(argc, argv); QGraphicsView view; QGraphicsScene scene; QGraphicsRectItem *item1 = scene.addRect(20, 20, 20, 20); QGraphicsRectItem *item2 = scene.addRect(50, 20, 20, 20); QPen pen1, pen2; pen1.setWidth(5); pen2.setWidth(5); pen1.setCosmetic(true); pen2.setCosmetic(false); item1->setPen(pen1); item2->setPen(pen2); view.setScene(&scene); view.scale(4, 4); // both rects are the same size, but one a has wider pen view.show(); return a.exec(); }
相关问答
更多-
在哪里实例化QPen并不重要。 QPen的默认宽度为0.这是一个特殊的值,这意味着化妆品是真实的,宽度实际上是1.所以,如果你不想让笔化妆,你必须将其设置为所需的宽度。 您可能还需要将化妆品设置为假。 这是一个简单的例子: #include
int main(int argc, char *argv[]) { QApplication a(argc, argv); QGraphicsView view; QGraphicsScene scene; QGr ... -
如果我正确理解您的问题,您需要的基本步骤是: 将Qt的原点概念转换为您想要缩放的位置,即左上角 然后应用比例 然后再翻译一下 If I understand your question correctly, the basic steps you'll need are: Translate Qt's idea of the origin to where you want to scale around, i.e. top-left Then apply the scale Then translate ...
-
我用它做了 void mousePressEvent(QGraphicsSceneMouseEvent *event) { myPath = new QGraphicsPathItem(); previous = event->scenePos(); QPainterPath p; p.moveTo(previous); myPath->setPath(p); this->addItem(myPath); } void ::mouseMoveEvent(QGraphicsSceneMouseEvent ...
-
你需要sceneRect不只是width和height 。 对于调整大小的缩放,您希望将插槽连接到sceneRectChanged以便在场景更改大小时调整图像大小。 或者你可以派生一个QGraphicsView并使用重写的updateSceneRect来更改图像大小,或者更好的是,只需重写drawBackground 。 You want sceneRect not just width and height. For the scaling on resize you want to connect a ...
-
if ( !m_click ) { QGraphicsView::mousePressEvent(e); } 只需调用父类的实现即可使用“正常”行为。 if ( !m_click ) { QGraphicsView::mousePressEvent(e); } Just call the parent class' implementation to use the 'normal' behaviour.
-
我必须在zoomout函数之前实现全局变量的初始化,如果在进入mouseMoveEvent时初始化了这个变量,那么我将直接退出该函数。 I had to implement the initialization of a global variable before the zoomout function, and if this variable was initialized when entering the mouseMoveEvent, then I would directly exit th ...
-
在showEvent中处理视图也适合: void TestApp::showEvent ( QShowEvent * event ) { view->fitInView(0, 0, scene->width(), scene->height()); QWidget::showEvent(event); } Handle the view fit also inside the showEvent: void TestApp::showEvent ( QShowEvent * event ) ...
-
橘子的QPen?(QPen in Orange?)[2024-02-18]
如果你看看QColor :: setNamedColor() ,它说: Sets the RGB value of this QColor to name, which may be in one of these formats: ... A name from the list of colors defined in the list of SVG color keyword names provided by the World Wide Web Consortium; for example, " ... -
根据文档 ,问题是因为你没有将sceneRect设置为QGraphicsScene : sceneRect:QRectF 此属性保存场景矩形; 场景的边界矩形 场景矩形定义场景的范围。 它主要由QGraphicsView用于确定视图的默认可滚动区域,以及由QGraphicsScene来管理项目索引。 如果未设置,或者设置为空QRectF,那么sceneRect()将返回场景创建后场景中所有项目的最大边界矩形(即,在项目添加到场景中或在场景中移动时增长的矩形,但永不畏缩)。 所以每次添加一条新线时,如果它大于 ...
-
缩放QGraphicsScene以填充整个QGraphicsView(Scaling the QGraphicsScene to fill whole QGraphicsView)[2022-03-05]
您可以创建继承自QGraphicsView的自定义类。 您应该在自定义QGraphicsView中重新实现resizeEvent(QResizeEvent * event),如: void MyView::resizeEvent(QResizeEvent *event) { fitInView(0, 0, 500, 500,Qt::KeepAspectRatio); QGraphicsView::resizeEvent(event); } 这样,视图将始终显示整个场景。 即,如果更改窗 ...