• TD button Group的实现


    1,用bool_button控件

    layout.ini

    main_win = {
        type = "window"
        x = 0
        y = 0
        w = 1024
        h = 600
        style = "main_win"
      flags={
        window_splash
      }
    
    
      audioBtn = {
        type = "bool_button"
        x = 10
        y = 10
        w = 172
        h = 70
        style = "audiobtn_style"
      }
    
      videoBtn = {
        type = "bool_button"
        x = 10
        y = 90
        w = 172
        h = 70
        style = "videobtn_style"
      }
    
      picBtn = {
        type = "bool_button"
        x = 10
        y = 170
        w = 172
        h = 70
        style = "picturebtn_style"
      }
    }
     

    2,style.rc

    bool_button.audiobtn_style {
    [nad]
    bg="./images/list_btn_music_n.png",stretch_normal
    [s]
    bg="./images/list_btn_music_p.png",stretch_normal
    }
    bool_button.videobtn_style {
    [nad]
    bg="./images/list_btn_video_n.png",stretch_normal
    [s]
    bg="./images/list_btn_video_p.png",stretch_normal
    }
    bool_button.picturebtn_style {
    [nad]
    bg="./images/list_btn_image_n.png",stretch_normal
    [s]
    bg="./images/list_btn_image_p.png",stretch_normal
    }

    2,用twRadioGroupAdd将控件加到一个组里面

    int main(int argc, const char *argv[])
    { TWidget *root;
        root = TwAppInit();
        signal(SIGTERM, &signal_handler);
         
        /*读取配置文件config.ini*/
        TwConfigParseFile(TGetExecutePath("../etc/config.ini"));
        TWidget *audioBtn = (TWidget*)TObjectGetFromName("audioBtn");
        TWidget *videoBtn = (TWidget*)TObjectGetFromName("videoBtn");
        TWidget *picBtn = (TWidget*)TObjectGetFromName("picBtn");
        TWidget *meidiaTypeGroup[3];
        meidiaTypeGroup[0] = audioBtn;
        meidiaTypeGroup[1] = videoBtn;
        meidiaTypeGroup[2] = picBtn;
        twRadioGroupAdd(meidiaTypeGroup, meidiaTypeGroup[0], "meidiatypegroup");
        twRadioGroupAdd(meidiaTypeGroup, meidiaTypeGroup[1], "meidiatypegroup");
        twRadioGroupAdd(meidiaTypeGroup, meidiaTypeGroup[2], "meidiatypegroup");
    
        TObjectAddEventHandler(audioBtn, CLICKED, click3func, (void *)"audioBtn");
        TObjectAddEventHandler(videoBtn, CLICKED, click3func, (void *)"videoBtn");
        TObjectAddEventHandler(picBtn, CLICKED, click3func, (void *)"picBtn");
        TwSetValue(picBtn, 1);
    TwMainLoop(); return 0; }

    3,通过TwSetValue设置控件的选中和非选中状态。

    static void click3func(void *obj, T_ID event, TTable *in, void *arg, TExist *exist)
    {
        const char *pbtn = (const char*)arg;
        TWidget *audioBtn = (TWidget*)TObjectGetFromName("audioBtn");
        TWidget *videoBtn = (TWidget*)TObjectGetFromName("videoBtn");
        TWidget *picBtn = (TWidget*)TObjectGetFromName("picBtn");
        printf("click3func---pbtn:%s
    ", pbtn);
        if(!strcmp(pbtn, "audioBtn"))
        {
            TwSetValue(audioBtn, 1);
            TwSetValue(videoBtn, 0);
            TwSetValue(picBtn, 0);
        }
        else if(!strcmp(pbtn, "videoBtn"))
        {
            TwSetValue(audioBtn, 0);
            TwSetValue(videoBtn, 1);
            TwSetValue(picBtn, 0);
        }
        else if(!strcmp(pbtn, "picBtn"))
        {
            TwSetValue(audioBtn, 0);
            TwSetValue(videoBtn, 0);
            TwSetValue(picBtn, 1);
        }
    }
  • 相关阅读:
    Python PyQt5 Pycharm 环境搭建及配置
    Python Appium 元素定位方法简单介绍
    unittest单元测试简单介绍
    什么是multipart/form-data请求
    new HttpClient().PostAsync封装参数
    httpPostedFile实现WEBAPI文件上传
    Asp.Net WebApi接口返回值IHttpActionResult
    Asp.Net WebApi上传图片
    如果项目在IIS发布后,出现System.ComponentModel.Win32Exception: 拒绝访问。
    C# ASP.NET 控制windows服务的 开启和关闭 以及重启
  • 原文地址:https://www.cnblogs.com/senior-engineer/p/14099241.html
Copyright © 2020-2023  润新知