EveryoneCallsMeM
21st March 2019, 14:49
Preface: I'm relatively new to C++ and coding in general, so my jargon and understanding of specific terminology is on the weaker side.
I'm having difficulty with understanding the proper syntax and functionality of filling a copy slot with the desired information. Basically my knowledge of Signals and Slots is not the best.
So, I'm working on an established app interface with tooltips in place that appear when hovering over an icon. I would like to create a right click event that would copy the tooltip message to the clipboard.
So far I have a contextMenuEvent() that has only a copy option and it properly appears when I right click on the icon. But where I get lost is, what do I have to input in the copy action to copy the tool tip message message itself?
void
SomeClass::SomeLabel::mouseMoveEvent( QMouseEvent *event )
{
Q_UNUSED( event );
// Show tooltip at a particular place of the icon, no matter where
// the mouse comes into the icon
QToolTip::showText( this->mapToGlobal( QPoint( this->minimumSize().width()/2, this->minimumSize().height()/2 ) ), this->toolTip(), this, this->rect() );
QLabel::mouseMoveEvent( event );
return;
}
// virtual
void
SomeClass::SomeLabel::contextMenuEvent( QContextMenuEvent *event )
{
QMenu menu;
menu.addAction( m_copyInvalidityMessage );
menu.exec( event->globalPos() );
return;
}
void
SomeClass::SomeLabel::copyInvalidityMessageAction( void )
{
m_copyInvalidityMessage = new QAction( QIcon( ":/application/Copy.ico" ), tr( "Copy Message" ), this );
connect( m_copyInvalidityMessage, SIGNAL( triggered( void ) ), this, SLOT( copyInvalidityTriggered( void ) ) );
return;
}
void
SomeClass::SomeLabel::copyInvalidityTriggered(void )
{
QApplication::clipboard()->setText( text() );
return;
}
My guess, which isn't a good guess at all, is that in copyInvalidityTriggered(void) the setText(text()) needs something? Any help or direction to documentation that may explain or show examples would be greatly appreciated. Thank you.
I'm having difficulty with understanding the proper syntax and functionality of filling a copy slot with the desired information. Basically my knowledge of Signals and Slots is not the best.
So, I'm working on an established app interface with tooltips in place that appear when hovering over an icon. I would like to create a right click event that would copy the tooltip message to the clipboard.
So far I have a contextMenuEvent() that has only a copy option and it properly appears when I right click on the icon. But where I get lost is, what do I have to input in the copy action to copy the tool tip message message itself?
void
SomeClass::SomeLabel::mouseMoveEvent( QMouseEvent *event )
{
Q_UNUSED( event );
// Show tooltip at a particular place of the icon, no matter where
// the mouse comes into the icon
QToolTip::showText( this->mapToGlobal( QPoint( this->minimumSize().width()/2, this->minimumSize().height()/2 ) ), this->toolTip(), this, this->rect() );
QLabel::mouseMoveEvent( event );
return;
}
// virtual
void
SomeClass::SomeLabel::contextMenuEvent( QContextMenuEvent *event )
{
QMenu menu;
menu.addAction( m_copyInvalidityMessage );
menu.exec( event->globalPos() );
return;
}
void
SomeClass::SomeLabel::copyInvalidityMessageAction( void )
{
m_copyInvalidityMessage = new QAction( QIcon( ":/application/Copy.ico" ), tr( "Copy Message" ), this );
connect( m_copyInvalidityMessage, SIGNAL( triggered( void ) ), this, SLOT( copyInvalidityTriggered( void ) ) );
return;
}
void
SomeClass::SomeLabel::copyInvalidityTriggered(void )
{
QApplication::clipboard()->setText( text() );
return;
}
My guess, which isn't a good guess at all, is that in copyInvalidityTriggered(void) the setText(text()) needs something? Any help or direction to documentation that may explain or show examples would be greatly appreciated. Thank you.