Home > Mobile >  Consult, how to control the size of the QChartView in QWidget?
Consult, how to control the size of the QChartView in QWidget?

Time:09-18

Modeled on the book of case writing, but the book USES the MainWindow, I need a QWidget,
But can the MainWindow setCentralWidget, but there was no find the similar function, QWidget
The book code (excerpts),


 
QChartView * chartView=new QChartView (this);//create ChartView
QChart * chart=new QChart ();//create a Chart
ChartView - & gt; SetChart (chart);//Chart is added to the ChartView
This - & gt; SetCentralWidget (chartView);//QWidget found no similar functions inside,


Lead to serious show my QChartView shrinkage in the upper left corner, is not complete,


The effect of the code book:

CodePudding user response:

CodePudding user response:

Remove the

CodePudding user response:

Qt documentation wrote:
SetCentralWidget
Sets the given widget to give priority to the center of the window the widget, note: QMainWindow obtain the ownership of the widget pointer, and at the appropriate time to delete it,

QWidget or at sizechange chartview resize or QHBoxLayout * hb=new QHBoxLayout (this);
Hb - & gt; AddWidget (chartView);

CodePudding user response:

ChartView - & gt; The resize (width, height);

CodePudding user response:

ChartView set sizepolicy

CodePudding user response:

Get the size of ChartView, and set to chart size:
 
//adjust sizeInt w=this - & gt; Width ();
Int h=this - & gt; Height ();
This - & gt; Chart () - & gt; SetGeometry (0, 0, w, h);

CodePudding user response:

According to not complete because you use code new out QChartView rasterize were not in the interface,
Available consider hauled out a Widget at the interface between the first, and then to rasterize it, then it is promoted to QChartView, then call it setChart function, put you create QChart in, should be able to solve this problem
  •  Tags:  
  • Qt