QListWidgetItem *item=new QListWidgetItem
item->setSizeHint(QSize(10,100))
ui->listWidget->addItem(item)
将QWidget对象与QListWidgetItem对象进行绑定
QWidget *w = new QWidget
QHBoxLayout *layout=new QHBoxLayout
QPushButton *pushButton=new QPushButton(w)
QCheckBox *checkBox=new QCheckBox(w)
layout->addWidget(checkBox)
layout->addWidget(pushButton)
w->setLayout(layout)
ui->listWidget->setItemWidget(item,w)
不解释,自己看。// myWidget is any QWidget-derived class
myWidget->setContextMenuPolicy(Qt::CustomContextMenu)
connect(myWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(ShowContextMenu(const QPoint&)))
void MyClass::ShowContextMenu(const QPoint& pos) // this is a slot
{
// for most widgets
QPoint globalPos = myWidget->mapToGlobal(pos)
// for QAbstractScrollArea and derived classes you would use:
// QPoint globalPos = myWidget->viewport()->mapToGlobal(pos)
QMenu myMenu
myMenu.addAction("Menu Item 1")
// ...
QAction* selectedItem = myMenu.exec(globalPos)
if (selectedItem)
{
// something was chosen, do stuff
}
else
{
// nothing was chosen
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)