Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Solved Expansion of Item in QGraphicsItem?

    General and Desktop
    3
    5
    1228
    Loading More Posts
    • 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.
    • S
      ShrikantAmbade last edited by

      Hello everyone,
      I want to expand my item which is root item, but I don't how to call expandItem method and get QGraphicsItem item for it.
      What exactly happening in my code and what I want is as follows:

      • I have a class called ImportXML.cpp in that class I am calling another class called ModelScene.cpp to draw one item element for example square by this methode
      void ModelScene::CreateItemFromXml(QString nodeName, QPointF scenepos )
      
      • In ModelScene.cpp there is another method called
      void ModelScene::expandItem(QGraphicsItem *parentItem, int size = 1)
      {
      	ModelItemExp *itemExp;
      	itemExp = new ModelItemExp(myItemType, size);
      	if(myItemType == ModelItem::Tuple) itemExp->setBrush(Qt::lightGray);
      		else itemExp->setBrush(Qt::white);
      	myPen.setColor(Qt::black);
      	myPen.setWidth(0);
      	itemExp->setPen(myPen);
      	itemExp->setParentItem(parentItem);
      	addItem(itemExp);
      	emit itemInserted(itemExp);
      	itemExp->setFlag(QGraphicsItem::ItemIsMovable, false);
      }
      

      which is responsible for expanding element. in this method parameter is parentItem. but I dont know how to pass this parentItem from my ImportXML.class?

      • and also in mainWindow there is another method for handling expansion but how to join this three class so that when I call createItemXml method from ImportXML.class it first draw a square and then expand that square with expandItem method from ImportXML class only.
        mainWindow class code is as follows for handling expansion:
      void MainWindow::handleExpansion(int expSize, int direction){
      	foreach (QGraphicsItem *item, scene->selectedItems()) {
      			scene->expandItem(item, expSize);}
      
      	QGraphicsItem *parentItem = scene->selectedItems().last();
      	QGraphicsItem *item = parentItem->childItems().first();
      	parentItem->setSelected(false);
      	item->setSelected(true);
      
      	int x; int y; int size;
      	if (direction==1){			// right
      		size = 0;
      		x = 250; y = 0;
      	}
      	else if (direction==2){		// top
      		size = item->boundingRect().height()*0.5;
      		rotate();
      		x = 0; y = -250;
      	}
      	else if (direction==3){		// bottom
      		size = item->boundingRect().height()*0.5;
      		rotate();
      		x = 0; y = 250;
      	}
      	item->setPos(x, y);
      	if (direction!=1) item->moveBy(size-100, 0);
      	scene->drawLine(parentItem, direction);
      	item->setSelected(false);
      }
      
      

      Many Thank in Advance

      1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators last edited by

        i don't quite understand your problem.
        Your ImportXML class takes a XML definition and creates QGraphicsItems from it? Am i right?
        And you want to know what QgraphicsItem was created for a specific XML element?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        S 1 Reply Last reply Reply Quote 0
        • S
          ShrikantAmbade @raven-worx last edited by

          @raven-worx ImportXML class is XML definition i.e reading of XML and inside ModelScene class I have method called CreateItemXML which can draw element graphically for me...

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @ShrikantAmbade last edited by

            @ShrikantAmbade
            Hi. To call function in main, you could
            define a new signal in your xml class and hook up to the
            mainwindows slots.
            That way you can activate methods from your XML class
            without having direct access to mainwindow.

            S 1 Reply Last reply Reply Quote 1
            • S
              ShrikantAmbade @mrjj last edited by

              @mrjj Thank you dear

              1 Reply Last reply Reply Quote 0
              • First post
                Last post