void QListWidget::setItemWidget(QListWidgetItem * item, QWidget * widget)
Sets the widget to be displayed in the given item.
This function should only be used to display static content in the place of a list widget item. If you want to display custom dynamic content or implement a custom editor widget, use QListView and subclass QItemDelegate instead.
上面的翻译:
该函数应该只用来在一个list widget item位置显示静态内容。如果你想要显示自定义动态内容或实现一个自定义编辑控件,使用QListView和子类化QItemDelegate代替。
1、这个问题我给你解答:添加一个按钮和一个listview,然后粘贴以下代码就可以检查checkbox是否打勾Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LVM_FIRST = &H1000
Private Const LVM_GETITEMSTATE = LVM_FIRST + 44
Private Const LVIS_SELECTED = &H2000
Private Sub Command1_Click()
Dim i As Integer
Dim l As Long
Dim s As String
For i = 0 To ListView1.ListItems.Count - 1
l = SendMessage(ListView1.hwnd, LVM_GETITEMSTATE, i, 0)
If (l And LVIS_SELECTED) >0 Then
s = s &ListView1.ListItems.Item(i + 1).Text &"选中" &vbCrLf
Else
s = s &ListView1.ListItems.Item(i + 1).Text &"未选中" &vbCrLf
End If
Next i
MsgBox s
End Sub
Private Sub Form_Load()
Dim X As ListItem
Dim i As Integer
ListView1.ColumnHeaders.Add , "A", "AAA"
ListView1.ColumnHeaders.Add , "B", "BBB"
ListView1.ColumnHeaders.Add , "C", "CCC"
For i = 1 To 10
Set X = ListView1.ListItems.Add
X.Text = "L" &i
X.SubItems(1) = "LA" &10 - i
X.SubItems(2) = "LB" &i
Next i
Dim l As Long
l = SendMessage(ListView1.hwnd, LVM_FIRST + 55, 0, 0)
l = l Or &H75
l = SendMessage(ListView1.hwnd, LVM_FIRST + 54, 0, l)
End Sub
2、每个项目后面都添加一个按钮或者checkbox是不可以的,windows系统层面上没有提供这个功能,并且你加上了也没有相关的API能获得其状态。
3、VC可以,VB做不到,VC的思路是,创建一个对话框资源,然后把自定义的功能加入到对话框里,然后再把打开对话框嵌入到这个窗口里(或者把自定义的功能嵌入到打开对话框里),并且你必须用API方式来启动通用对话框而不是控件(网上有流传API显示打开窗口的方法,不过超级麻烦),这种嵌入对话框的方法在VB里目前还没有看到有效的简单的方法可以实现,但是VC可以
欢迎你加我百度HI或者QQ(在我的百度空间里有)来讨论第三个问题,第三个问题不是完全没有可能,第二个是完全没可能实现的
自定义控件HorizontalListView,横向的ListView http://blog.csdn.net/hexingzhi/article/details/7578707 详细可以参考这个,有图解教程,希望可以帮到你欢迎分享,转载请注明来源:内存溢出
评论列表(0条)