[SOLVED] Combobox menu question
when i right click the QComboBox, is there a way for me to add the “delete field” to the menu?
11 replies
Here is a code snippet that should get you going. At first, i thought you wanted a context menu on the actual list dropping down, but after re-reading, I figure that you want to extend the menu on the line edit part. Here is some code doing that. Note that it only works for editable comboboxes. For non-editable ones, it will crash.
The header that goed with it is trivial, so not shown.
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- qDebug() << "Current context menu policy:" << ui->comboBox->contextMenuPolicy();
- connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem()));
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::deleteItem()
- {
- qDebug() << "we should delete this item";
- }
- {
- menu->addSeparator();
- menu->addAction(m_deleteAction);
- menu->popup(pnt);
- connect(menu, SIGNAL(aboutToHide()), menu, SLOT(deleteLater()));
- }
You must log in to post a reply. Not a member yet? Register here!


