Home > other >  Qtcreator5.2.0 QGraphicsView pictures showed is not successful
Qtcreator5.2.0 QGraphicsView pictures showed is not successful

Time:10-31

The code is as follows: QGraphicsScene scene; The QGraphicsRectItem * itemrect=new QGraphicsRectItem,0,100,100 (0); Scene. The addItem (itemrect); Scene. SetBackgroundBrush (Qt: : blue); The UI - & gt; GraphicsView - & gt; SetScene (& amp; Scene); The UI - & gt; GraphicsView - & gt; show(); Operation interface shows nothing, I am a beginner, please everybody to give directions, thank!

CodePudding user response:

Copy the code # include & lt; QApplication> #include #include #include Int main (int arg c, char * argv []) {QApplication a (arg c, argv); QGraphicsScene scene; QGraphicsView view; The QGraphicsRectItem * itemrect=new QGraphicsRectItem,0,100,100 (0); Scene. The addItem (itemrect); Scene. SetBackgroundBrush (Qt: : blue); The setScene (& amp; Scene); The show (); Return a.e xec (); } blue background, hollow inside a black box,

CodePudding user response:

Thank you very much for your reply, I just tried, but why can't show in my project so out figure? I am built a MainWindow project, based on the main interface to add a TabWidget controls, in the first TAB to add the QTreeView and QGrapgicsView, want to display in the QGrapgicsView loading picture, why not

CodePudding user response:

In my project the main function of the code in also don't show, but to create a new line, I don't know to is why

CodePudding user response:

Thank you all for your attention, problem solving, the scene as a global variable or class member variables, don't set it to the local variables in the function, is set to a local variable variable is the end of the word function, so can't display images,

CodePudding user response:

The above is correct,,,,
  • Related