一、QCPAxisRect
1.多个QCPAxisRect对齐:
QCPAxisRect* R00 = new QCPAxisRect(m_pCustomPlot);
QCPMarginGroup *marginGroup = new QCPMarginGroup(m_pCustomPlot);
R00->setAutoMargins(QCP::MarginSide::msLeft | QCP::MarginSide::msRight);
R00->setMarginGroup(QCP::msLeft | QCP::MarginSide::msRight, marginGroup);
2.让QCPAxisRect四个轴都显示
R00->setupFullAxesBox(true);
3.刻度号显示在内测
R00->axis(QCPAxis::atBottom)->setTickLabelSide(QCPAxis::LabelSide::lsInside);
R00->axis(QCPAxis::atLeft)->setTickLabelSide(QCPAxis::LabelSide::lsInside);
4.QCPItemStraightLine展示在单个QCPAxisRect上
auto pHorReffer = new QCPItemStraightLine(m_pCustomPlot);
pHorReffer->setClipToAxisRect(true);
pHorReffer->setClipAxisRect(R00);
pHorReffer->point1->setAxes(R00->axis(QCPAxis::atBottom), R00->axis(QCPAxis::atLeft));
pHorReffer->point2->setAxes(R00->axis(QCPAxis::atBottom), R00->axis(QCPAxis::atLeft));
二.QCPItemText
1.QCPItemText坐标依赖于软件位置
this->position->setType(QCPItemPosition::ptAbsolute);
设置用pixel坐标
2.QCPItemText坐标依赖于QCustomplot坐标
this->position->setType(QCPItemPosition::ptPlotCoords);
设置用coord坐标
三.qss设置
背景设置
1.图片大,控件小,图片显示不全
border-image: url(:/frontload/assets/images/oneUp.png);
使用border-image,不要用background-image
切换背景图:
样式表
QPushButton#pull-down,
QPushButton[classes~="pull-down"],
QPushButton {
min-width: 100px;
max-width: 100px;
background: #F0F0F0;
background-image: url(:/icon/pull-down.png);
background-repeat: no-repeat;
background-position: left center;
color: black;
border: 0px;
}
QPushButton#pull-right,
QPushButton[classes~="pull-right"],
QPushButton {
min-width: 100px;
max-width: 100px;
background: #F0F0F0;
background-image: url(:/icon/pull-right.png);
background-repeat: no-repeat;
background-position: left center;
color: black;
border: 0px;
}
代码
void ToolPlane::updataWgtStyle(QWidget* wgt, QString pro, QString val)
{
if (wgt == nullptr) {
return;
}
wgt->setProperty(pro.toStdString().c_str(), val);
wgt->style()->unpolish(wgt); // 清除旧的样式
wgt->style()->polish(wgt); // 更新为新的样式
wgt->update();
}
切换
updataWgtStyle(m_btnFold, "classes", "pull-down");
updataWgtStyle(m_btnFold, "classes", "pull-right");