Link to home
Start Free TrialLog in
Avatar of nrholder
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!!
Avatar of rew_
rew_

Cant you connect to the
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
Avatar of nrholder

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(QIconViewItem*)), this, SLOT(slotIconViewItemClick()));

Here's the slot implementation:

void MyApp::slotIconViewItemClick()
{
     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
Avatar of rew_
rew_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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(QIconViewItem*) ), this, SLOT( slotIconViewItemClick(QIconViewItem*) ) );
     }

Then here's the slot:

void MyApp::slotIconViewItemClick(QIconViewItem *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