PDA

View Full Version : Getting a pointer to a leftclicked QTextEdit



stan_fr
24th November 2010, 13:14
Hello,

I am new to QT and trying to find a way to manage multiple QTextEdits with the same functions ...

To be more specific I do have 12 QTextEdits inside the same QFrame, and would like to use my same own set of functions listed in a pop-up menu, to manage the 12 QtextEdits instead of writing twleve times this set of functions.

In order to be able to do so I "just" need a mean to get a QtextEdit * to the QtextEdit I left click in, but I can't find a way to do it.

Any help would be welcomed :)

SixDegrees
24th November 2010, 13:24
You could broadcast a signal from the event handler, but you might want to have a look at QSignalMapper first.

franz
24th November 2010, 13:25
In any case there's always the QWidget::customContextMenuRequested(QPoint) (http://doc.trolltech.com/latest/qwidget.html#customContextMenuRequested) signal. The QPoint is most likely in widget coordinates, so a QTextEdit::mapToParent(QPoint) call should give you the correct place to show the context menu.

stan_fr
24th November 2010, 14:16
You could broadcast a signal from the event handler, but you might want to have a look at QSignalMapper first.

Well : it would be a very clever solution but QTextEdit does not have any signal related to mouse buttons ...

I can find in which QTextEdit I am by mapping the cursor position to global coordinates and finding which QTextEdit it belongs to but I envisonned something "cleaner" ...

Thanks anyway.

SixDegrees
24th November 2010, 16:18
Well : it would be a very clever solution but QTextEdit does not have any signal related to mouse buttons ...

I can find in which QTextEdit I am by mapping the cursor position to global coordinates and finding which QTextEdit it belongs to but I envisonned something "cleaner" ...

Thanks anyway.

Yes, that's why I suggested emitting the signal from an event handler.

And again, you should have a look at QSignalMapper before going too much further.

franz
24th November 2010, 19:38
Well : it would be a very clever solution but QTextEdit does not have any signal related to mouse buttons ...
It does (somewhat) and it's called customContextMenuRequested().


I can find in which QTextEdit I am by mapping the cursor position to global coordinates and finding which QTextEdit it belongs to but I envisonned something "cleaner" ...


void MyWidget::showContextMenu(const QPoint &p)
{
QTextEdit *editor = qobject_cast<QTextEdit *>(sender());
if (!editor)
return;
//...
}