请教虚表里的hover的问题

cat 1天前 77

请教下以下代码:


import win.ui;
import godking.vlistEx;
/*DSG{{*/
mainForm = win.form(text="vlistEx - table adapter";right=849;bottom=578)
mainForm.add(
vlist={cls="vlistEx";left=10;top=10;right=840;bottom=570;db=1;dl=1;dr=1;dt=1;edge=1;transparent=1;z=1}
)
/*}}*/

var t = { fields={"序号","姓名","年龄","地址","身份证","操作"} };
for(i=1;100;1){
    var tt={};
	tt["序号"]="[@rowindex]";  // 行序号标记是不允许编辑修改的
	tt["姓名"]=math.random(1000,9999)+"姓名";
	tt["年龄"]=math.random(10,99);
	tt["地址"]=math.random(1000,9999)+"地址";
	tt["身份证"]=math.random(1000,9999)+"身份证";
	tt["操作"] = ""
	..table.push(t,tt);
}


itemModel = {

  	{   /* 矩形元素定义 */
        type="rect",
        rectf={x=80;y=1;width=36;height=20},
        fillcolor=0xFFe7e5e4,
        width=1,
        round=5,
        smooth=true
    },
    {   /* 文本元素定义 */
        type="text",
        rectf={x=80;y=1;width=36;height=20},
        name="title",
        text="应用",
        font={name="微软雅黑",h=16,color=0xFF555555}, 
        itemhoverfont={name="微软雅黑",h=16,color=0xFFBB0000},
        valign=1,
        align=1,
        smooth=false,
        ellipsion = true;
    },
    {   /* 矩形元素定义 */
        type="rect",
        rectf={x=126;y=1;width=36;height=20},
        fillcolor=0xFFe7e5e4,
        width=1,
        round=5,
        smooth=true
    },
     {   /* 文本元素定义 */
        type="text",
        rectf={x=126;y=1;width=36;height=20},
        name="title",
        text="下载",
        font={name="微软雅黑",h=16,color=0xFF555555}, 
        itemhoverfont={name="微软雅黑",h=16,color=0xFFBB0000},
        valign=1,
        align=1,
        smooth=false,
        ellipsion = true;
    }
}



mainForm.vlist.setTable(t,,{80,100,100,100,200},0x2);
mainForm.vlist.checkBox.show = true;
mainForm.vlist.textColor = 0x000000;
mainForm.vlist.setHeaderHeight(50);
mainForm.vlist.headerAlign = 1;
//mainForm.vlist.lineColorH = 0x008800;
//mainForm.vlist.lineColorV = 0xBB9999;
mainForm.vlist.fillParent();
mainForm.vlist.selectedBkColor = 0xFFFFFF
mainForm.vlist.setColumnType(6/*列号*/,7/*_vlistEx_ColType_OwnerDrawCustom*/,itemModel/*参考godking.customPlus中的itemModel定义规则*/ );
mainForm.vlist.onEditBegin = true; 
mainForm.vlist.onEditEnd = function(row/*行*/,col/*列*/,text/*内容*/){
	/*单元格编辑完毕,是否允许单元格内容改变。返回false不允许,返回true允许,返回文本则改为新文本*/
	/*不定义此事件,则默认允许改变。注意:只有onEditBegin事件返回true,此事件才会触发。*/
	// 确保第三列输入数值!
	if col==3 {
		var r = ..tostring((..tonumber(text)):0);
		if r!=text	{
			..win.msgbox(text++" 将转为:"++r);
			return r; 
		}
	}
	return true; 
}

mainForm.vlist.ownerDrawCustom = function (row,col,text/*当前单元格文本*/){
    return {       
        
    }
}

mainForm.vlist.onSortColumn = function(col,desc){
	/*点击列标题进行排序。col:列号,从1开始。desc:是否倒序。*/
	owner.sort( col, desc, 0 /*数据转换:0默认 1时间 2数值 3文本*/ ,false /*使用微软api进行文本排序*/ );
}
mainForm.vlist.onRClick = function(row/*行*/,col/*列*/){
	/*鼠标右键点击项目事件*/
	..win.msgbox("您鼠标右键点击了:"++row++"行,"++col++"列");
}
mainForm.show();
win.loopMessage();


为什么鼠标滑过最后一列,里面的2个按钮的颜色同时都变了?而且根本不是滑过按钮才变色,是只要滑过最后一列就变色?


跟认知的不一样,是哪里有问题吗?

最新回复 (3)
  • 光庆 19小时前
    0 2

    需要在 ItemModel 中设置该元素的 hover = true; 并 设置对应的 hoverfont(滑过元素),而不是用 itemhoverfont (滑过单元格)。

    import win.ui;
    import godking.vlistEx;
    /*DSG{{*/
    mainForm = win.form(text="vlistEx - table adapter";right=849;bottom=578)
    mainForm.add({
    vlist={cls="vlistEx";left=10;top=10;right=840;bottom=570;db=1;dl=1;dr=1;dt=1;edge=1;transparent=1;z=1}
    })
    /*}}*/
    
    var t = { fields={"序号","姓名","年龄","地址","身份证","操作"} };
    for(i=1;100;1){
        var tt={};
        tt["序号"]="[@rowindex]";  // 行序号标记是不允许编辑修改的
        tt["姓名"]=math.random(1000,9999)+"姓名";
        tt["年龄"]=math.random(10,99);
        tt["地址"]=math.random(1000,9999)+"地址";
        tt["身份证"]=math.random(1000,9999)+"身份证";
        tt["操作"] = ""
        ..table.push(t,tt);
    }
    
    
    itemModel = {
    
          {   /* 矩形元素定义 */
            type="rect",
            rectf={x=80;y=1;width=36;height=20},
            fillcolor=0xFFe7e5e4,
            width=1,
            round=5,
            smooth=true
        },
        {   /* 文本元素定义 */
            type="text",
            rectf={x=80;y=1;width=36;height=20},
            name="title",
            text="应用",
            hover = true;
            font={name="微软雅黑",h=16,color=0xFF555555}, 
            hoverfont={name="微软雅黑",h=16,color=0xFFBB0000},
            valign=1,
            align=1,
            smooth=false,
            ellipsion = true;
        },
        {   /* 矩形元素定义 */
            type="rect",
            rectf={x=126;y=1;width=36;height=20},
            fillcolor=0xFFe7e5e4,
            width=1,
            round=5,
            smooth=true
        },
         {   /* 文本元素定义 */
            type="text",
            rectf={x=126;y=1;width=36;height=20},
            name="title",
            text="下载",
            hover = true;
            font={name="微软雅黑",h=16,color=0xFF555555}, 
            hoverfont={name="微软雅黑",h=16,color=0xFFBB0000},
            valign=1,
            align=1,
            smooth=false,
            ellipsion = true;
        }
    }
    
    mainForm.vlist.setTable(t,,{80,100,100,100,200},0x2);
    mainForm.vlist.checkBox.show = true;
    mainForm.vlist.textColor = 0x000000;
    mainForm.vlist.setHeaderHeight(50);
    mainForm.vlist.headerAlign = 1;
    //mainForm.vlist.lineColorH = 0x008800;
    //mainForm.vlist.lineColorV = 0xBB9999;
    mainForm.vlist.fillParent();
    mainForm.vlist.selectedBkColor = 0xFFFFFF
    mainForm.vlist.setColumnType(6/*列号*/,7/*_vlistEx_ColType_OwnerDrawCustom*/,itemModel/*参考godking.customPlus中的itemModel定义规则*/ );
    mainForm.vlist.onEditBegin = true; 
    
    mainForm.vlist.onEditEnd = function(row/*行*/,col/*列*/,text/*内容*/){
        /*单元格编辑完毕,是否允许单元格内容改变。返回false不允许,返回true允许,返回文本则改为新文本*/
        /*不定义此事件,则默认允许改变。注意:只有onEditBegin事件返回true,此事件才会触发。*/
        // 确保第三列输入数值!
        if col==3 {
            var r = ..tostring((..tonumber(text)):0);
            if r!=text    {
                ..win.msgbox(text++" 将转为:"++r);
                return r; 
            }
        }
        return true; 
    }
    mainForm.vlist.ownerDrawCustom = function (row,col,text/*当前单元格文本*/){
    	/* 当列类型为7(_vlistEx_ColType_OwnerDrawCustom)时,调用本函数获取itemModel中定义的各元素的绘制内容。
    	   返回值格式可参考 godking.customPlus 中的 itemList 中项目的定义格式。
    	   支持绘制:img、text、rect、line 四种类型的元素。
    	   支持定义:正常、hover、itemhover 三种状态的属性值。
    	   启动鼠标悬浮状态的元素,要在itemModel中设置hover=true,鼠标点击事件中的buttonIndex为该元素的hover索引。
    	   启用鼠标悬浮的各元素的rectf,可以完全不重叠或完全重叠,但不建议部分重叠。*/
        return {元素名称1='\a.png';元素名称2={text='元素文本';font=font1;hoverfont=font2;itemhoverfont=font3}}; 
    }
    
    mainForm.vlist.onSortColumn = function(col,desc){
        /*点击列标题进行排序。col:列号,从1开始。desc:是否倒序。*/
        owner.sort( col, desc, 0 /*数据转换:0默认 1时间 2数值 3文本*/ ,false /*使用微软api进行文本排序*/ );
    }
    
    mainForm.vlist.onClick = function(row/*行*/,col/*列*/,x,y,buttonIndex/*按钮区域序号*/){
    	/*鼠标左键点击项目事件。x、y为鼠标相对于虚表的坐标。
    	  按钮区域序号为:使用 setButtonRects() 或 setColumnButtonRects() 添加的按钮区域的序号,
          或:列类型为 OwnerDrawCustom 时 hover=true 的元素的序号。
    	  如果 editOnClick=true 则该事件完毕后会触发 onEditBegin 事件。
    	  返回 true 则强制跳过 onEditBegin 事件*/
    	import console
    	console.dump(row/*行*/,col/*列*/,x,y,buttonIndex/*按钮区域序号*/)
    }
    
    mainForm.show();
    win.loopMessage();


  • cat 18小时前
    0 3
    itemhoverfont 是划过整个这个列的单元格吗?我 itemhoverfont 是写在rect里面的 按说应该 是划过这个rect啊 感谢大佬.
  • 光庆 18小时前
    0 4
    cat itemhoverfont  是划过整个这个列的单元格吗?我 itemhoverfont  是写在rect里面的 按说应该 是划过这个rect啊 感谢大佬.

    划过该列的某个单元格。每个单元格里面,都包含itemModel列表中定义的一系列元素。

返回