Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGrahicsItem: problem with ItemIsMovable (dragging rectangle bigger than item itself)
QtWS25 Last Chance

QGrahicsItem: problem with ItemIsMovable (dragging rectangle bigger than item itself)

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    penpen
    wrote on last edited by
    #1

    Hello,

    I have a problem with a QGraphicsItem in a QGraphicsScene. What I would like is to be able to move the item with mouse. But the problem is that in my case, the dragging rectangle is bigger than the item itself.

    Here is the code that I use:

    @
    class Test: public QGraphicsView
    {
    public:
    Test();

    private:
    virtual void resizeEvent (QResizeEvent * event);
    QGraphicsScene* m_pScene;
    };
     
    Test::Test()
    {
    m_pScene = new QGraphicsScene();
    setScene(m_pScene);
     
    m_pScene->setSceneRect(0, 0, 100, 100);
     
    for (int i = 0 ; i < 10 ; i++)
    {
    QGraphicsRectItem * pItem = new QGraphicsRectItem();
    pItem->setFlag(QGraphicsItem::ItemIsMovable);
    pItem->setBrush(QBrush(QColor(190, 100, 100)));
    pItem->setRect(QRectF(10*i, 10, 5, 80.f));
    pItem->setCursor(Qt::SizeAllCursor);
    m_pScene->addItem(pItem);
    }
     
     
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     
    resize(600, 200);
    fitInView(scene()->sceneRect());
    show();
    }
     
    void Test::resizeEvent(QResizeEvent * event)
    {
    QGraphicsView::resizeEvent(event);
    fitInView(scene()->sceneRect());
    }
    

    @

    So when I run my program I have this window, and I can drag items. All seems ok.
    !http://img841.imageshack.us/img841/6579/screen1is.jpg()!

    But if I look closer the dragging zone is bigger than the item itself. (see the blue rectangle on following screenshot) The blue rectangle means that If I move the mouse in this rectangle, the cursor changes, and I can drag the item.
    !http://img842.imageshack.us/img842/8181/screen2pd.jpg()!

    I have the feeling that the problem is related to the "fitInView(scene()->sceneRect());" line. If I remove it, then it works.
    If I add a 'scale(5,1)' for example, there is the same problem.

    Do you have an idea of what the problem could be? Am I doing something wring with coordinates?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bunjee
      wrote on last edited by
      #2

      Reproduced it on my side.

      When you scale a very smal sceneRect, you get a strange selection area on your scaled QGraphicsRectItem(s).

      Could this be a bug ? Should we file a bug report ?

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bunjee
        wrote on last edited by
        #3

        Reported here: http://bugreports.qt.nokia.com/browse/QTBUG-17985

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stephenju
          wrote on last edited by
          #4

          It's causing a lot of problem since my scene has really high scale level. I cooked up some patches and submitted a merge request. It doesn't seem to be looked at yet. Graphics view bugs tend to be slow acted on for some reason. Maybe it's a really complicated system?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            stephenju
            wrote on last edited by
            #5

            Well. The MR has been submitted for 10 days and nothing happens. What's the expected time for someone to look at it and see if it's worth merging? I see a lot of MRs that are months old without even a comment from developers.

            Here's the link if anyone is interested: https://qt.gitorious.org/qt/qt/merge_requests/2591

            1 Reply Last reply
            0
            • S Offline
              S Offline
              stephenju
              wrote on last edited by
              #6

              I butchered the MR in response to a Troll's comment. Here's the new one:
              https://qt.gitorious.org/qt/qt/merge_requests/2594

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved