Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert QChartView in form with Qt Designer?

I want to add QChart to the form. But I can't find it in the Widget Box. So I created it in the code. How can I insert it in QWidget or QFrame or something else?

I want to set area of that widget in QtDesigner.

like image 362
Ufx Avatar asked Jan 21 '18 01:01

Ufx


People also ask

How do I add my logo to QT?

You drag and drop your Label on your window, select the Label, you'll see on the right side of your screen the 'Property Editor' frame and the 'QLabel' menu, you click on pixmap => Choose File..., select a file and that's it.

How do I add widgets to Qt?

To add widgets in Qt Designer: In the Qt Creator Editor mode, double-click the notepad. ui file in the Projects view to launch the file in the integrated Qt Designer. Drag and drop widgets Text Edit (QTextEdit) to the form.


1 Answers

Option 1: Promoted

I suppose you mean inserting a QChartView, because QChartView inherits from QGraphicsView, this would be a good option, for this we do the following:

  1. first add QT += charts in the .pro
  2. place the QGraphicsView to the design.
  3. Right click on the QGraphicsView and select Promote to...
  4. When doing the above, a menu appears, in the menu it should be set in QChartView in Promoted Class Name, and QtCharts in Header file, then press the add button and finally press promote.

Screenshots of some steps:

[3.]

enter image description here

[4.1]

enter image description here

[4.2]

enter image description here

The same could be done using QWidget as a base instead of QGraphicsView.

Why is one or another widget chosen as a base?

It is chosen because Qt Designer through moc establishes certain properties by default, and if the widget does not have that method then it will not compile. as all widgets inherit from QWidget this would be the basis for any new widget to promote it in Qt Designer.

In the following link you will find an example.


Option 2: QtChart plugin

Another option would be to compile the QtChart plugin for QtDesigner, for it you must download the 5 files from the following link:

enter image description here

Then you execute the following:

qmake make sudo make install 

At the end you can access QtCharts::QChartView in Qt Designer

enter image description here

like image 176
eyllanesc Avatar answered Sep 23 '22 15:09

eyllanesc