Skip to content
  • 0 Votes
    2 Posts
    3k Views
    Chris KawaC

    It would be nice to say what self and event are. I'm guessing a QGraphicsItem and a parameter of QGraphicsSceneMouseEvent? Is that right?

    If so then event.pos() and event.scenePos() are not exchangeable. The first one is cursor position in item's coordinates and the second one cursor position in scene coordinates. They are the same only when item is placed at (0,0). If item is moved they will differ. It's important to note that these values are what they were at the time the event took place, which might be different from the "current" values for item (this is a good thing). For example if you move your mouse fast and there are a lot of events generated the cursor position in these events will be a little behind the actual current position of the cursor before they "catch up".

    As for self.scenePos() - this is the position of the item in the scene. This is the point relative to which the event.pos() is calculated. It is not necessary the top left of the bounding rect. It can be placed anywhere using 'setTransformOriginPoint()'. It is often set to the center of the item. For example if you have a bunch of draggable circles a center is probably more convenient than a top left corner. For vertical bars on a chart the origin might be placed at the middle bottom of a bar etc.

  • 0 Votes
    3 Posts
    3k Views
    F

    @kenchan I knew that.

    I want not stacking by z-order, I want simultaneous stacking.

    It works something like that by default (if opacity of items is 0.5 )

    output = Merge(Merge(background, 0.5 × item1), 0.5 × item2)

    I want something like that

    output = Merge(background, 0.5 × item1, 0.5 × item2)

    aka simultaneous merge items to scene, so it not depends from z-order.
    (example — I want ⅓ background, ⅓ item1 and ⅓ item2, Indifferently to items z-order)

  • 0 Votes
    1 Posts
    1k Views
    No one has replied
  • 0 Votes
    2 Posts
    1k Views
    ?

    Hi! The way to convert your matrix to a QPixmap is to convert it to QImage first (e.g. using void QImage::setPixel(const QPoint &position, uint index_or_rgb)) and then convert the QImage to a QPixmap (using [static] QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags = Qt::AutoColor)).

  • 0 Votes
    4 Posts
    2k Views
    SGaistS

    How are you loading these lines ?

  • Select Line items easier

    Unsolved General and Desktop
    2
    0 Votes
    2 Posts
    778 Views
    AlvaroSA

    Edit: I have checked that if coordinates are [0.3 0.5 0.3 0.9] and I set pen.widthf bigger, then I can select much better the lines, but if the coordinates are [30 50 30 90] that does not work...

  • 0 Votes
    6 Posts
    3k Views
    mrjjM

    @AlvaroS
    ok. seems a bit messy.
    Do you really need a QGraphicsScene then ?
    You could also draw it as a custom control. you need zooming etc ?

    In any case, did u see this example
    http://doc.qt.io/qt-5/qtwidgets-graphicsview-diagramscene-example.html

    it even has arrowhead class :)

  • Move line in a scene

    Solved General and Desktop
    3
    0 Votes
    3 Posts
    2k Views
    AlvaroSA

    @mrjj hi my friend. You helped me a lot. That works fine!!!!!!!
    Superb!!!!!!!
    Thanks again

  • Draw a head arrow

    Unsolved General and Desktop
    2
    0 Votes
    2 Posts
    12k Views
    mrjjM

    The sample
    http://doc.qt.io/qt-5/qtwidgets-graphicsview-diagramscene-example.html
    has arrow class.
    Maybe it can provide inspiration.

  • 0 Votes
    7 Posts
    3k Views
    AlvaroSA

    @mrjj Yes it seems that...
    So now it is solved ;)

    Thanks a lot.

  • Save Graphics View Scene

    Unsolved General and Desktop
    6
    0 Votes
    6 Posts
    5k Views
    ?

    bool QPixmap::save(const QString & fileName, const char * format = 0, int quality = -1) const

    "If format is 0, an image format will be chosen from fileName's suffix." (see QPixmap documentation)

    So you can say pixmap.save("/home/pw/myfile.jpg") and it will automatically detect the ".jpg" suffix. If you want to save the image without a suffix you must specify what file format you want to use: pixmap.save("/home/pw/myfile", "JPG") (see supported file formats).

  • 0 Votes
    1 Posts
    694 Views
    No one has replied
  • [SOLVED]Move QRectF

    Solved General and Desktop
    10
    0 Votes
    10 Posts
    3k Views
    ?

    Glad you solved it! :-)

  • Update scene

    Solved General and Desktop
    34
    0 Votes
    34 Posts
    10k Views
    A

    I know I'm late to the party, but for what it's worth:

    There is rarely ever a need to manually update the GraphicsScene. It will automatically update parts whenever you move items (setPos), or change properties of ready-to-use items such as QGraphicsRectItem If you implement your own item and your own paint method, naturally the scene cannot know which properties will affect the paint and which won't. Therefore, you just call update() on the item after you changed any properties that affect the way the item looks If you change the boundingRect(), don't forget to call prepareGeometryChange(), otherwise you will have nasty painting effects Re sorting: qSort, anyone?
  • 0 Votes
    7 Posts
    2k Views
    SGaistS

    Ok, so what happened before is that the item you added was destroyed before it could be shown

  • 0 Votes
    4 Posts
    6k Views
    A

    @alex_malyu
    Thank you very much alex. I just tried what you suggested and it works perfectly.

    @SGaist
    I thought about slots and timer too, as suggested in the examples on qt's site, but it requires subclassing a QGraphicsItem for each item in the QGraphicsView. The problem is, I don't know the number of items that will be generated until runtime, and apart from this, creating 10.000 classes (one for each item) would be very resource intensive, I think.
    Anyway, the method above, the one with
    QCoreApplication::processEvents () ;
    works perfectly for my purpose.
    So thanks both for your politeness: it is very nice to see such a great community :)

  • 0 Votes
    3 Posts
    2k Views
    p3c0P

    Hi @Pheelbert,
    Make use of QQuickWindow::beforeRendering signal to draw the OpenGL stuff beneath QML scene.
    Have a look at this flow for more info, especially Pt. no. 8 and the example suggested by @SGaist.