在QListWidget中动态创建Row
你好,
我想创建一个自定义小部件。请帮忙提供一些想法。
我的目的是制作一个显示一些信息的列表小部件,当单击特定行时,它必须通过在所选行下方立即创建一个新区域(行或文本编辑)并将其他行拉到所选行下方来显示与该行对应的详细信息创建新区域后向下行。
在附件中,当我单击行 Nancy(将其视为行)时,她的详细信息将显示在所选行的下方。请对此提供帮助
Hi,
I want to create a custome widget. Please help by giving some idea.
My intention is to make a Listwidget which shows some Information and when clicking particulat row it have to show the details coresponding to that row by creating a new area(Row or text edit) immediately below the selected row and pull the other rows below the selected row to down after the created new area.
In attachment when I click row Nancy (consider it as row) her details is coming below the selected row. Please help on this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您要使用的是 QTreeView。它能够显示带有文本和图标的行。
您需要为表定义 QStandardItemModel,这将为其提供列定义。
以下是我为类似应用程序编写的类中的三个相关函数。请注意,我不需要在行中使用任何图像,因此您必须自己弄清楚该部分。
What you want to use is the QTreeView. It is capable of showing rows with text and icons.
You need to define the QStandardItemModel for the table, this will give it column definition.
Below are three relevant functions from a class I wrote for a similar app. Note that I did not need to use any images in my rows so you'll have to figure that part out yourself.
您可能想尝试使用自定义委托来查看行。我相信代表们知道他们是否被选中。使用此功能,您可以正常绘制未选定的行,并为选定的行绘制更多信息。问题是我不知道您是否可以在选择时调整小部件的大小。如果没有,QTreeView 解决方案应该仍然有效。
You may want to try using a custom delegate to view the rows. I believe the delegates know if they are selected. Using this, you would draw the unselected rows normally, and draw more information for the selected rows. The problem with this is that I don't know if you can resize the widget on selection. If not, the QTreeView solution should still work.