Results 1 to 6 of 6

Thread: Getting a pointer to a leftclicked QTextEdit

  1. #1
    Join Date
    Nov 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Question Getting a pointer to a leftclicked QTextEdit

    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

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Getting a pointer to a leftclicked QTextEdit

    You could broadcast a signal from the event handler, but you might want to have a look at QSignalMapper first.

  3. #3
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Getting a pointer to a leftclicked QTextEdit

    In any case there's always the QWidget::customContextMenuRequested(QPoint) 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.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  4. #4
    Join Date
    Nov 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Getting a pointer to a leftclicked QTextEdit

    Quote Originally Posted by SixDegrees View Post
    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.

  5. #5
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Getting a pointer to a leftclicked QTextEdit

    Quote Originally Posted by stan_fr View Post
    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.

  6. #6
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Getting a pointer to a leftclicked QTextEdit

    Quote Originally Posted by stan_fr View Post
    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" ...
    Qt Code:
    1. void MyWidget::showContextMenu(const QPoint &p)
    2. {
    3. QTextEdit *editor = qobject_cast<QTextEdit *>(sender());
    4. if (!editor)
    5. return;
    6. //...
    7. }
    To copy to clipboard, switch view to plain text mode 
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

Similar Threads

  1. this pointer
    By freekill in forum Newbie
    Replies: 10
    Last Post: 30th January 2010, 02:17
  2. QTextEdit: get word under the mouse pointer?
    By zorro68 in forum Qt Programming
    Replies: 4
    Last Post: 13th November 2009, 16:42
  3. attaching user data pointer to images in QTextEdit
    By Workeml in forum Qt Programming
    Replies: 0
    Last Post: 7th November 2008, 21:06
  4. Replies: 1
    Last Post: 16th February 2007, 08:22
  5. pointer
    By mickey in forum General Programming
    Replies: 4
    Last Post: 1st September 2006, 01:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.