gpt4 book ai didi

c++ - QListWidget的QT C++ SelectedIndex

转载 作者:行者123 更新时间:2023-11-28 05:14:39 24 4
gpt4 key购买 nike

如何获取 QListWidget 的选定索引。我可以获得选定的颜色,但现在确定如何获得项目的选定索引。我已经编写了选定的颜色函数。请帮助我获取选定的颜色索引。

ColorList::ColorList(QWidget *parent)
: QListWidget(parent)
{
init();
}

QString ColorList::selectedColor() const
{
return currentItem() ? currentItem()->data(Qt::UserRole).toString() : QString();
}

void ColorList::init()
{
setFrameShape(QFrame::NoFrame);

QMap<QString, QString> names;

names["Air"] = "#FFFFFF";
names["Resist"] ="#B22222";
names["BARC"] = "#F2CBC5";
names["Oxide"] = "#34AAD1";
names["Low"] = "#FD7E00";


// add color names and their icons
foreach(const QString &key, names.keys())
{
QPixmap px(16,16);
px.fill(QColor(names[key]));

QListWidgetItem *item = new QListWidgetItem(QIcon(px), key);
item->setData(Qt::UserRole, names[key]);
addItem(item);
}
}

最佳答案

它是 currentRow()。请在此处查看文档 http://doc.qt.io/qt-4.8/qlistwidget.html#currentRow-prop

关于c++ - QListWidget的QT C++ SelectedIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42915927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com