Article directory
We choose
widget
Above is the selected QT Froms
template
we can choose
QT设计师界面类
Adjust the length in the horizontalLayout component in QT
where
0,0
is the constant width
Use custom controls in other components
About ComboBox
controls
ui->comboBox->addItem(QString("字符串"));
About QStringList
QStringList longerList = (QStringList() << str1 << str2 << str3);
ico add failed
Add this paragraph to xhcj.rc:
IDI_ICON ICON DISCARDABLE "ico的名称.ico"
Get the windows port number
pro file (add)
QT += core gui serialport
cpp file (add)
#include<QtSerialPort/QSerialPort>
#include<QtSerialPort/QSerialPortInfo>
#include <QDebug>//这个可不添加
QList<QSerialPortInfo> serial_list = QSerialPortInfo::availablePorts();
QStringList com_list;
int serialsize = serial_list.size();
qDebug() << serial_list.size();//打印长度
for(int i = 0;i<serialsize;i++)
{
QString flag = serial_list.at(i).description();
//description()的功能:类型转换,将QSerialPortInfo类型转换成QString类型,description()的功能
qDebug()<<i<<flag;
if(flag == "USB 串行设备"){
qDebug() << serial_list.at(i).portName();//输出端口号
com_list = QStringList()<< serial_list.at(i).portName();
}
}
About the form
Need to install
QWT
, please refer to the detailed installation steps ; QWT download address
Set the background cloth (ui interface)
QLinearGradient gradient(0,0,0,400);
gradient.setColorAt(1,QColor(90,90,90));
gradient.setColorAt(0.38,QColor(105,105,105));
gradient.setColorAt(1,QColor(70,70,70));
ui->qwtPlot->setCanvasBackground(QBrush(gradient));
set grid
QwtPlotGrid *grid = new QwtPlotGrid;
grid->enableXMin( true );
grid->setMajorPen( Qt::gray, 0, Qt::DotLine );
grid->setMinorPen( Qt::darkGray, 0, Qt::DotLine );
grid->attach( ui->qwtPlot );
.h file
#ifndef FFTLEARN_H
#define FFTLEARN_H
#include <QWidget>
#include "qwt_plot.h"
#include "qwt_plot_grid.h"
//#include <qwt_legend.h>
//#include <qwt_legend_label.h>
//#include <qwt_plot_legenditem.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_textlabel.h>
#include <qwt_plot_zoomer.h>
//#include <qwt_scale_draw.h>
//#include <qwt_plot_renderer.h>
//#include <QMessageBox>
namespace Ui {
class fftLearn;
}
class fftLearn : public QWidget
{
Q_OBJECT
public:
explicit fftLearn(QWidget *parent = 0);
virtual ~fftLearn();
private:
int CurNum;
QVector<QwtPlotCurve *> m_curve;
QwtPlotZoomer *m_zoomer[2];
QwtPlotTextLabel *InfoLabel;
private:
Ui::fftLearn *ui;
void InsertLegnd();
void SetZoom();
private slots:
// void showItem(const QVariant &itemInfo,bool on);
};
#endif // FFTLEARN_H