nrholder
asked on
QIconView Slots and Signals
I have an icon view which will have many icons populated at run-time and these are user configurable, and they can add/delete icons.
I need to connect the double-click signal of the correct QIconViewItem to a slot. I would like to only have one slot and connect all QIconViewItems to it and then execute an action based on the specific icon clicked.
I can't figure this out. I can connect all QIconViewItems to a single slot but I can't parse them.
Please help!!
I need to connect the double-click signal of the correct QIconViewItem to a slot. I would like to only have one slot and connect all QIconViewItems to it and then execute an action based on the specific icon clicked.
I can't figure this out. I can connect all QIconViewItems to a single slot but I can't parse them.
Please help!!
ASKER
I've tried that but I must be doing something wrong.
Here's what I have:
(void) new QIconViewItem(IconView1, tr(NewLine), image0);
connect(IconView1, SIGNAL(doubleClicked(QIcon ViewItem*) ), this, SLOT(slotIconViewItemClick ()));
Here's the slot implementation:
void MyApp::slotIconViewItemCli ck()
{
qWarning("Not implemented yet!");
}
Whenever I try to return a pointer to the new IconViewItem and pass it to the SIGNAL it fails. I am pretty new at C/C++. Any suggestions you have would be helpful but code samples would be better :-).
Here's what I have:
(void) new QIconViewItem(IconView1, tr(NewLine), image0);
connect(IconView1, SIGNAL(doubleClicked(QIcon
Here's the slot implementation:
void MyApp::slotIconViewItemCli
{
qWarning("Not implemented yet!");
}
Whenever I try to return a pointer to the new IconViewItem and pass it to the SIGNAL it fails. I am pretty new at C/C++. Any suggestions you have would be helpful but code samples would be better :-).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's awesome! I have one more small question on the side if you a moment. Everytime I doubleclick the item it returns the value I query equal to the number of items I have. Here's the code I use to create the icons. I pull the data from a file in their home directory and parse it.
while (!feof(pFile))
{
(void) fgets(Line, 100, pFile); /* snag the line from pFile, return in pLine */
if (feof(pFile)) { break; } /* don't overrun */
size_t len = strcspn(Line, delim); /* get length of name */
char NewLine[100] = ""; /* allocate storage for cut string */
strncpy (NewLine, Line, len);
(void) new QIconViewItem( IconView1, tr(NewLine), image0 );
connect( IconView1, SIGNAL( doubleClicked(QIconViewIte m*) ), this, SLOT( slotIconViewItemClick(QIco nViewItem* ) ) );
}
Then here's the slot:
void MyApp::slotIconViewItemCli ck(QIconVi ewItem *item)
{
qWarning( item->text() );
}
For example I have 3 icons named Icon1, Icon2, Icon3. If I doubleclick Icon2, qWarning displays:
Icon2
Icon2
Icon2
Any help would be appreciated!
Thanks!
Nick
while (!feof(pFile))
{
(void) fgets(Line, 100, pFile); /* snag the line from pFile, return in pLine */
if (feof(pFile)) { break; } /* don't overrun */
size_t len = strcspn(Line, delim); /* get length of name */
char NewLine[100] = ""; /* allocate storage for cut string */
strncpy (NewLine, Line, len);
(void) new QIconViewItem( IconView1, tr(NewLine), image0 );
connect( IconView1, SIGNAL( doubleClicked(QIconViewIte
}
Then here's the slot:
void MyApp::slotIconViewItemCli
{
qWarning( item->text() );
}
For example I have 3 icons named Icon1, Icon2, Icon3. If I doubleclick Icon2, qWarning displays:
Icon2
Icon2
Icon2
Any help would be appreciated!
Thanks!
Nick
void doubleClicked ( QIconViewItem * item ) signal? This will send you the actual item that was doubled clicked. After that you do what you want with the QIconViewItem