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. Qt4 Book Example Malfunctions in Qt5
Forum Updated to NodeBB v4.3 + New Features

Qt4 Book Example Malfunctions in Qt5

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.3k Views 2 Watching
  • 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.
  • ModelTechM Offline
    ModelTechM Offline
    ModelTech
    wrote on last edited by
    #1

    I have taken the Diagram example from chapter 4 of the Qt4 book on C++ GUI programming with Qt4 and got it to compile and run with Qt5.7 using Qt Creator 4.1.0. The example code suggests that the links between the nodes should be updated whenever the nodes are repositioned on the canvas. Unfortunately, this does not happen when I try this. Has anybody else tried this example? I am eager to know how to make it work...

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      That sounds like this example
      http://doc.qt.io/qt-5/qtwidgets-graphicsview-diagramscene-example.html

      1 Reply Last reply
      0
      • ModelTechM Offline
        ModelTechM Offline
        ModelTech
        wrote on last edited by
        #3

        I am referring to a different one. It looks like (showing also the malfunction).

        Diagram Application

        I believe that I downloaded the code from http://www.informit.com/store/c-plus-plus-gui-programming-with-qt4-9780132354165

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          Yes, it looks like 99% the same example :)

          Except the newer sample using different shapes than just nodes and
          the arrows moves with the shapes.

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #5

            Hi
            Had a quick look at the old sample
            Seems it never tell when node is updated in

            QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
            {
            qDebug() << "Node::itemChange:" << change;

            if (change == ItemPositionHasChanged) {
                qDebug() << "Node::itemChange: Pos Changed";  <<<<<<<<<<<<< this code is never run
                foreach (Link *link, myLinks)
                    link->trackNodes();
            }
            

            and it only gives
            Node::itemChange: ItemSelectedHasChanged
            Node::itemChange: ItemSelectedChange

            So its never detected its move and links not adjusted via trackNodes

            So it turns out the sample needs
            setFlag( QGraphicsItem::ItemSendsScenePositionChanges, true );

            in Node constructor and then it works ;)

            Node::Node()
            {
                myTextColor = Qt::darkGreen;
                myOutlineColor = Qt::darkBlue;
                myBackgroundColor = Qt::white;
            
                setFlags(ItemIsMovable | ItemIsSelectable);
                setFlag( QGraphicsItem::ItemSendsScenePositionChanges, true ); <<<< needed 
            }
            
            
            1 Reply Last reply
            3
            • ModelTechM Offline
              ModelTechM Offline
              ModelTech
              wrote on last edited by
              #6

              Great! That extra flag indeed solves it :)

              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