You are not logged in.

vcernobai

Trainee

  • "vcernobai" is male
  • "vcernobai" started this thread

Posts: 57

Location: Iasi, Romania

Occupation: Project Manager

  • Send private message

1

Monday, November 16th 2009, 9:31am

Delete an item from QComboBox

Hello guys,

I have some little troubles when deleting random items with Key_Delete. The signal/slots mechanism doesn't work like I expected.

I do the following:

Quoted

QAction *delComboAction = new QAction(connectionsComboBox);
delComboAction->setShortcut(QKeySequence::Delete);
connect(delComboAction, SIGNAL(triggered()), SLOT(removeItemFromComboBox()));


and

Quoted

void RssDownloader::removeItemFromComboBox()
{
if (connectionsComboBox->count() > 0 && connectionsComboBox->hasFocus()) connectionsComboBox->removeItem(connectionsComboBox->currentIndex());
}


My problems are the following:

1. The delComboAction is triggered (with a few exceptions which I will present immediately below) no matter where the current focus is and even if I assigned the parent for this QAction to be connectionsComboBox. I expected my QAction to be triggered only for my QComboBox;

2. When I expand the connectionsComboBox to see the whole list of items and select a specific one to delete, the QAction can not be triggered. It even doesn't receive any keyPressEvents. Should I reimplement the QComboBox? I would avoid as much as possible such things as they are time-consuming compared to the problem itself if there are any other "intelligent" solutions. I checked the signal highlighted(int index) emitted from connectionsComboBox and it works just fine, but it doesn't help me as I need the Delete key to work;

Does somebody know how to deal with this tricky situation?

Many thanks in advance for any kind of suggestions!

Cheers,
Victor

vcernobai

Trainee

  • "vcernobai" is male
  • "vcernobai" started this thread

Posts: 57

Location: Iasi, Romania

Occupation: Project Manager

  • Send private message

2

Monday, November 16th 2009, 9:46pm

Finally, I solved this problem, but I got another in the meantime: the pop-up does not ajust it's height automatically when deleting an item ... this only happens when closing and opening back the pop-up.

Does anybody knows what's the solution? I've tried with sizeHint, adjustSize, updateGeometry and nothing worked.

Thanks in advance!

vcernobai

Trainee

  • "vcernobai" is male
  • "vcernobai" started this thread

Posts: 57

Location: Iasi, Romania

Occupation: Project Manager

  • Send private message

3

Monday, November 16th 2009, 10:40pm

Okay, I just solved the last problem as well. Just call QComboBox::showPopup() after each delete key event and everything is ok. 8)