尝试状态值自动

This commit is contained in:
hm
2021-04-25 09:28:46 +08:00
parent efdc426f39
commit 8374802b69
7 changed files with 82 additions and 22 deletions
+18 -1
View File
@@ -16,9 +16,11 @@ StateGroup::StateGroup(int index,QWidget *parent) : QWidget(parent)
layout = new QGridLayout(box);
layout->setMargin(3);
layout->setHorizontalSpacing(6);
layout->setVerticalSpacing(6);
box->setLayout(layout);
m_lenght += layout->margin() * 2;
}
@@ -31,6 +33,17 @@ StateGroup::~StateGroup()
void StateGroup::addItem(StateWidget * w)
{
if(ItemList.size() >= 1)
{
//为什么减2
m_lenght += w->height() + layout->verticalSpacing() - 2;
qDebug() << this->height() << w->height() << layout->verticalSpacing();
}
else
{
m_lenght += w->height();
}
ItemList.insert(ItemList.size(),w);//逐渐往上加
if(layout)
@@ -60,6 +73,8 @@ void StateGroup::removeItem(int index)
{
StateWidget *w = ItemList.value(index);
m_lenght -= w->height() + layout->verticalSpacing();
delete w;
}
}
@@ -68,6 +83,8 @@ void StateGroup::removeItem(StateWidget * w)
{
if(ItemList.values().contains(w))
{
m_lenght -= w->height() + layout->verticalSpacing();
delete w;
}
}
+11
View File
@@ -81,6 +81,13 @@ public slots:
return ItemList.size();
}
int lenght(void)
{
return m_lenght;
}
private slots:
@@ -102,6 +109,10 @@ private:
QGridLayout *toplayout = nullptr;
QGridLayout *layout = nullptr;
int m_lenght = 0;
};
#endif // STATEGROUP_H
+8 -8
View File
@@ -9,7 +9,7 @@ StateWidget::StateWidget(int flag,int index,QWidget *parent) : QWidget(parent)
title = new QLabel("new status");
title->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
title->setFixedSize(w/2,h+offset);
title->setFixedSize(w/2,h+m_offset);
gridlayout->addWidget(title,0,0,1,1);
@@ -17,7 +17,7 @@ StateWidget::StateWidget(int flag,int index,QWidget *parent) : QWidget(parent)
{
label = new QLabel("0");
label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
label->setFixedSize(w/2,h+offset);
label->setFixedSize(w/2,h+m_offset);
setColor(state::gray);
gridlayout->addWidget(label,0,1,1,1);
}
@@ -27,12 +27,12 @@ StateWidget::StateWidget(int flag,int index,QWidget *parent) : QWidget(parent)
bar->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
bar->setRange(0,100);
bar->setValue(0);
bar->setFixedSize(w/2,h+offset);
bar->setFixedSize(w/2,h+m_offset);
gridlayout->addWidget(bar,0,1,1,1);
}
this->setLayout(gridlayout);
this->resize(w,h+ 2 * offset);
this->resize(w,h+ 2 * m_offset);
}
StateWidget::StateWidget(int flag, QString t,QVariant v,state s,int index, QWidget *parent) : QWidget(parent)
@@ -47,7 +47,7 @@ StateWidget::StateWidget(int flag, QString t,QVariant v,state s,int index, QWidg
title = new QLabel(t);
title->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
title->setFixedSize(w/2,h+offset);
title->setFixedSize(w/2,h+m_offset);
gridlayout->addWidget(title,0,0,1,1);
@@ -55,7 +55,7 @@ StateWidget::StateWidget(int flag, QString t,QVariant v,state s,int index, QWidg
{
label = new QLabel(v.toString());
label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
label->setFixedSize(w/2,h+offset);
label->setFixedSize(w/2,h+m_offset);
setColor(s);
gridlayout->addWidget(label,0,1,1,1);
}
@@ -66,12 +66,12 @@ StateWidget::StateWidget(int flag, QString t,QVariant v,state s,int index, QWidg
bar->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
bar->setRange(0,100);
bar->setValue(v.toDouble());
bar->setFixedSize(w/2,h+offset);
bar->setFixedSize(w/2,h+m_offset);
gridlayout->addWidget(bar,0,1,1,1);
}
this->setLayout(gridlayout);
this->resize(w,h + 2 * offset);
this->resize(w,h + 2 * m_offset);
}
+5 -2
View File
@@ -68,7 +68,10 @@ public slots:
return title->text();
}
int offset(void)
{
return m_offset;
}
void setColor(state s);
@@ -86,7 +89,7 @@ private:
int w = 300;
int h = 20;
int offset = 2;
int m_offset = 2;
double max = 99999999999999999;
double min = -99999999999999999;
+35 -10
View File
@@ -109,6 +109,9 @@ StatusUI::StatusUI(QWidget *parent) :
}
basewidth = this->width();
}
StatusUI::~StatusUI()
@@ -122,25 +125,47 @@ void StatusUI::resizeEvent(QResizeEvent *event)
//计算一个使用多少长度
/*
if(GroupList.size() > 0)
{
int row = 0;
int column = 0;
int current_height = 0;
this->resize(basewidth,this->height());
for( QMap<int,StateGroup *>::iterator i = GroupList.begin();i != GroupList.end();i++)
{
StateGroup *g = i.value();
//ui->gridLayout->addWidget(g,g->ID(),0,1,1);
//
qDebug() << g->size() << g->lenght();
if((current_height + g->lenght()) < this->height())
{
ui->gridLayout->addWidget(g,row,column,1,1);
row++;
current_height += g->lenght();
}
else
{
current_height = 0;
column ++;
row = 0;
this->resize(this->width() * (column+1),this->height());
}
qDebug() << g->size();
}
/*
QVBoxLayout * vb = new QVBoxLayout;
vb->addStretch();
ui->gridLayout->addLayout(vb,GroupList.size(),0,1,1);
*/
}
*/
}
+2 -1
View File
@@ -53,9 +53,10 @@ private:
QMap<int,StateGroup *> GroupList;
//QList<StateGroup *> GroupList;
int basewidth = 0;
};
+3
View File
@@ -26,6 +26,9 @@
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
</layout>
</widget>
<resources/>