Image 如何在WXLISTCRL(多栏报告样式)中显示图像
我已经成功地创建了带有图标或多栏文本的wxlistctrl,如下所示 现在我想在左边文本列表的每一行添加一个图标。我认为这应该是可能的,因为典型的wxWidgets应用程序,如code::blocks和wxSmith,经常在列表/树视图(资源浏览器窗口)甚至笔记本的选项卡(编译器日志窗口)中显示图标。 那么我怎样才能创造出这样的东西呢?(大家都知道Windows资源管理器) 我试过这个Image 如何在WXLISTCRL(多栏报告样式)中显示图像,image,icons,wxwidgets,Image,Icons,Wxwidgets,我已经成功地创建了带有图标或多栏文本的wxlistctrl,如下所示 现在我想在左边文本列表的每一行添加一个图标。我认为这应该是可能的,因为典型的wxWidgets应用程序,如code::blocks和wxSmith,经常在列表/树视图(资源浏览器窗口)甚至笔记本的选项卡(编译器日志窗口)中显示图标。 那么我怎样才能创造出这样的东西呢?(大家都知道Windows资源管理器) 我试过这个 SetImageList (ToolImages, wxIMAGE_LIST_NORMAL); Inser
SetImageList (ToolImages, wxIMAGE_LIST_NORMAL);
InsertColumn (0, "Icon");
SetColumnWidth (0, 40);
...
for (int i=0; i<5; i++)
{
InsertItem (i, i);
SetItemColumnImage (i, 0, i);
SetItem (i, 1, IntToStr (i+1));
...
SetImageList(工具图像,wxIMAGE\u LIST\u正常);
插入列(0,“图标”);
设置列宽(0,40);
...
对于(int i=0;i是的,这是可能的,并且演示了如何执行,特别是请参见MyFrame::InitWithReportItems()
函数。代码的唯一区别似乎是您使用了不同的InsertItem()
重载,因此您可能应该改用InsertItem(i,”
)
还要检查您的图像列表中是否有5个图标
更一般地说,尝试减少代码与(工作)示例之间的差异几乎总能很快找到问题所在。谢谢,VZ,但我发现不是InsertItem()而是SetImageList()。我的图像列表是正确的,但“which”参数不是。将wxIMAGE\u LIST\u NORMAL替换为wxIMAGE\u LIST\u SMALL可以解决问题!我认为“SMALL”只适用于SMALL\u图标模式和“NORMAL”应该是默认值。但是,是的,这是有道理的,普通图标很大,不适合文本显示。如果文档告诉我们在经过很长时间的尝试和错误之后…这是一个使用WXLISTCTRL的小图标视图的简单示例。请将此代码放在类声明中。我是在基于框架的Windows应用程序中完成的使用代码块执行应用程序。这将对您有用
wxImageList*il=newwximagelist(32,32,false,0);
wxImageList*i2=新的wxImageList(32,32,false,0);
wxDir目录(wxGetCwd());
wxdir1(wxGetCwd());
如果(!dir.IsOpened())
{
//在此处处理错误-wxDir将已记录错误消息
//解释失败的确切原因
返回;
}
如果(!dir1.IsOpened())
{
//在此处处理错误-wxDir将已记录错误消息
//解释失败的确切原因
返回;
}
puts(“正在枚举当前目录中的对象文件:”);
wxString路径、文件名、目录串、文件名1、目录串1、img、imgPath、路径1、img1、imgPath1;
int i=0;
path=wxT(“C:\\testing\\splitterwindow\\set\\devices”);
路径1=wxT(“C:\\testing\\splitterwindow\\set\\actions”);
img=wxT(“C:\\testing\\splitterwindow\\set\\devices\\”;
img1=wxT(“C:\\testing\\splitterwindow\\set\\actions\\”;
bool cont=直接打开(路径);
boolcont1=dir1.Open(路径1);
cont=dir.GetFirst(&filename,wxEmptyString,wxDIR\u DEFAULT);
Append(filename.c_str());
cont1=dir1.GetFirst(&filename1,wxEmptyString,wxDIR\u DEFAULT);
dirstring1.Append(filename1.c_str());
while(续)
{
imgPath.clear();
cont=dir.GetNext(&filename);
Append(filename.c_str());
//构造映像路径
Append(img.c_str());
Append(filename.c_str());
//现在,将图像添加到imagelist
il->Add(wxBitmap(wxImage(imgPath.c_str()));
i++;
}
while(续1)
{
imgPath1.clear();
cont1=dir1.GetNext(&filename1);
dirstring1.Append(filename1.c_str());
//构造映像路径
imgPath1.Append(img1.c_str());
Append(filename1.c_str());
//现在,将图像添加到imagelist
i2->Add(wxBitmap(wxImage(imgPath1.c_str()));
i++;
}
//将imagelist分配给listctrl
ListCtrl1->AssignImageList(il,wxIMAGE\u LIST\u SMALL);
ListCtrl3->AssignImageList(i2,wxIMAGE\u LIST\u SMALL);
对于(int j=0;jGetImageCount()-1;j++)
{
wxListItem itemCol;
项目集合集合ID(j);
itemCol.SetImage(j);
itemCol.SetAlign(wxLIST_格式_左);
ListCtrl1->InsertItem(itemCol);
}
对于(int k=0;kGetImageCount()-1;k++)
{
WxlistItemCol1;
itemCol1.SetId(k);
itemCol1.SetImage(k);
itemCol1.SetAlign(wxLIST_格式_左);
ListCtrl3->InsertItem(itemCol1);
}
`您提到的示例已经不见了。您还有其他教程给我吗?
wxDir dir(wxGetCwd());
wxDir dir1(wxGetCwd());
if ( !dir.IsOpened() )
{
// deal with the error here - wxDir would already log an error message
// explaining the exact reason of the failure
return;
}
if ( !dir1.IsOpened() )
{
// deal with the error here - wxDir would already log an error message
// explaining the exact reason of the failure
return;
}
puts("Enumerating object files in current directory:");
wxString path, filename, dirstring,filename1, dirstring1, img,imgPath,path1,img1,imgPath1;
int i=0;
path=wxT("C:\\testing\\splitterwindow\\set\\devices");
path1=wxT("C:\\testing\\splitterwindow\\set\\actions");
img=wxT("C:\\testing\\splitterwindow\\set\\devices\\");
img1=wxT("C:\\testing\\splitterwindow\\set\\actions\\");
bool cont=dir.Open(path);
bool cont1=dir1.Open(path1);
cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DEFAULT);
dirstring.Append(filename.c_str());
cont1 = dir1.GetFirst(&filename1, wxEmptyString, wxDIR_DEFAULT);
dirstring1.Append(filename1.c_str());
while ( cont )
{
imgPath.clear();
cont = dir.GetNext(&filename);
dirstring.Append(filename.c_str());
// Consturct the imagepath
imgPath.Append(img.c_str());
imgPath.Append(filename.c_str());
//Now, add the images to the imagelist
il->Add(wxBitmap(wxImage(imgPath.c_str())));
i++;
}
while ( cont1 )
{
imgPath1.clear();
cont1 = dir1.GetNext(&filename1);
dirstring1.Append(filename1.c_str());
// Consturct the imagepath
imgPath1.Append(img1.c_str());
imgPath1.Append(filename1.c_str());
//Now, add the images to the imagelist
i2->Add(wxBitmap(wxImage(imgPath1.c_str())));
i++;
}
//assigning the imagelist to listctrl
ListCtrl1->AssignImageList(il, wxIMAGE_LIST_SMALL);
ListCtrl3->AssignImageList(i2, wxIMAGE_LIST_SMALL);
for(int j=0;j < il->GetImageCount()-1;j++)
{
wxListItem itemCol;
itemCol.SetId(j);
itemCol.SetImage(j);
itemCol.SetAlign(wxLIST_FORMAT_LEFT);
ListCtrl1->InsertItem(itemCol);
}
for(int k=0;k < i2->GetImageCount()-1;k++)
{
wxListItem itemCol1;
itemCol1.SetId(k);
itemCol1.SetImage(k);
itemCol1.SetAlign(wxLIST_FORMAT_LEFT);
ListCtrl3->InsertItem(itemCol1);
}