QT学习之旅 - 自定义控件


在这里插入图片描述
在这里插入图片描述
我们选择 widget

在这里插入图片描述
在这里插入图片描述
以上是选QT Froms的模板

我们可以选择QT设计师界面类
在这里插入图片描述

QT中horizontalLayout组件中调整长度

在这里插入图片描述

其中0,0是等宽

在其他组件中使用自定义控件

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

关于ComboBox控件

在这里插入图片描述

ui->comboBox->addItem(QString("字符串"));
关于QStringList
QStringList longerList = (QStringList() << str1 << str2 << str3);

ico添加失败

在这里插入图片描述

xhcj.rc中添加这一段:

IDI_ICON ICON DISCARDABLE "ico的名称.ico"

在这里插入图片描述

获取windows端口号

pro文件(添加)
QT       += core gui serialport
cpp文件(添加)
#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();
  }
}

关于表格

需要安装QWT,安装详细步骤可参考; QWT下载地址

在这里插入图片描述

设置背景布(ui界面)
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));
设置网格
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文件
#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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

结城明日奈是我老婆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值