C++ QmodelIndex和头数据
在我的ui屏幕中有4个TableView。在4个视图的标题数据函数中,我只需要一个1行名称-视图1和3的温度,以及四行名称字段1x、字段4x、字段10x和字段40x。 我的职能是C++ QmodelIndex和头数据,c++,qt,user-interface,qt-creator,C++,Qt,User Interface,Qt Creator,在我的ui屏幕中有4个TableView。在4个视图的标题数据函数中,我只需要一个1行名称-视图1和3的温度,以及四行名称字段1x、字段4x、字段10x和字段40x。 我的职能是 virtual QVariant headerData(int section,Qt::Orientation orientation, int role = Qt::DisplayRole) const { switch(role) {
virtual QVariant headerData(int section,Qt::Orientation orientation,
int role = Qt::DisplayRole) const
{
switch(role)
{
case Qt::DisplayRole:
switch (orientation)
{
case Qt::Vertical:
switch (m_channel)
{
case 0:
switch (section) // Range
{
case 0:
return "Temperature1";
}
case 1:
switch (section) // Range
{
case 0:
return "Field 1x range";
case 1:
return "Field 4x range";
case 2:
return "Field 10x range";
case 3:
return "Field 40x range";
}
case 2:
switch (section) // Range
{
case 0:
return "Temperature2";
}
case 3:
switch (section) // Range
{
case 0:
return "Field 1x range";
case 1:
return "Field 4x range";
case 2:
return "Field 10x range";
case 3:
return "Field 40x range";
}
但是,编译时的屏幕显示温度,视图1和视图3的字段4x、字段10x、字段40x,我不会这样做
请帮助您的
开关
语句中缺少中断。例如:
switch (m_channel)
{
case 0:
switch (section) // Range
{
case 0:
return "Temperature1";
}
break; // <-- You need this.
case 1:
...
开关(m_通道)
{
案例0:
开关(段)//量程
{
案例0:
返回“温度1”;
}
break;//我尝试使用break语句,而在编译时,我得到的是温度,2,3,4,而不是垂直头中的温度。