show后禁止点击其他界面:
Dialog->setWindowModality(Qt::ApplicationModal);
Dialog->show();
QStringList排序:
qSort(QStringList.begin(), QStringList.end())
qDebug()<<QStringList;
设置阴影边框:
QGraphicsDropShadowEffect *mGraphicsDropShadowEffect= new QGraphicsDropShadowEffect(this);
mGraphicsDropShadowEffect->setOffset(0, 0);
mGraphicsDropShadowEffect->setColor(QColor(38, 78, 119, 127));
mGraphicsDropShadowEffect->setBlurRadius(22);
ui->frame_->setGraphicsEffect(mGraphicsDropShadowEffect);
串口读取:
QSerialPort *mSerialPort = new QSerialPort();//串口对象
connect(mSerialPort,SIGNAL(readyRead()),this,SLOT(readSerialPortData()));
mSerialPort->setPortName(MyUtils::getConfigParams("serialPort"));
mSerialPort->setBaudRate(MyUtils::getConfigParams("baudRate").toInt(),QSerialPort::AllDirections);//波特率和读写方向
mSerialPort->setDataBits(QSerialPort::DataBits(MyUtils::getConfigParams("dataBit").toInt()));
mSerialPort->setFlowControl(QSerialPort::NoFlowControl);//无流控制
if(MyUtils::getConfigParams("checkBit") == "无"){
mSerialPort->setParity(QSerialPort::NoParity);
}else if(MyUtils::getConfigParams("checkBit") == "奇校验"){
mSerialPort->setParity(QSerialPort::OddParity);
}else{
mSerialPort->setParity(QSerialPort::EvenParity);
}
mSerialPort->setStopBits(QSerialPort::StopBits(MyUtils::getConfigParams("stopBit").toInt()));
if(mSerialPort->isOpen() && !mSerialPort->open(QIODevice::ReadWrite))
{
qDebug()<<"打开串口失败!";
MyToast::showTip("打开串口失败",this);
return false;
}
tableview操作:
mPrintStandardItemModel->setColumnCount(2);//设置列数
mPrintStandardItemModel->setRowCount(5);//设置行数
ui->printDataTableView->setModel(mPrintStandardItemModel);
ui->printDataTableView->horizontalHeader()->hide();//列名隐藏
ui->printDataTableView->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);//字体居中
ui->printDataTableView->verticalHeader()->setDefaultSectionSize(30);//固定行高度为6
ui->printDataTableView->verticalHeader()->setVisible(false); //列表头不可见
ui->printDataTableView->setShowGrid(true);//表中网格线可见
ui->printDataTableView->horizontalHeader()->setStyleSheet("QHeaderView::section {height: 30px;color:black;border: 1px solid #D8D8D8;background-color: rgb(225, 225, 225);}");
ui->printDataTableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->printDataTableView->setEditTriggers(QAbstractItemView::NoEditTriggers);//不可编辑
ui->printDataTableView->setSelectionBehavior(QAbstractItemView::SelectRows); //整行选中的方式
ui->printDataTableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);
ui->printDataTableView->setColumnWidth(0, 100);//设置固定宽度
tableview 单元格不显示选中:
void on_addTableView_clicked(const QModelIndex &index)
{
ui->addTableView->clearSelection();
ui->addTableView->clearFocus();
}