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. Expansion of Item in QGraphicsItem?
Forum Updated to NodeBB v4.3 + New Features

Expansion of Item in QGraphicsItem?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.5k Views 1 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.
  • S Offline
    S Offline
    ShrikantAmbade
    wrote on last edited by
    #1

    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
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      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
      0
      • raven-worxR raven-worx

        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?

        S Offline
        S Offline
        ShrikantAmbade
        wrote on last edited by
        #3

        @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...

        mrjjM 1 Reply Last reply
        0
        • S ShrikantAmbade

          @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...

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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
          1
          • mrjjM mrjj

            @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 Offline
            S Offline
            ShrikantAmbade
            wrote on last edited by
            #5

            @mrjj Thank you dear

            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