Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to tell if a user is _currently_ mouse-selecting text in QPlainTextEdit?

How to tell if a user is _currently_ mouse-selecting text in QPlainTextEdit?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 281 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Drew W
    wrote on last edited by
    #1

    I can get the cursor and check hasSelection(), but this only tells me if there is text selected. Not whether the user is currently in the process of selecting something. I would like something that evaluates to currentlySelecting:

    hasSelection = false
    currentlySelecting = false
    // user holds mouse button
    hasSelection = false
    currentlySelecting = false
    // user drags mouse to select text
    hasSelection = true
    currentlySelecting = true
    // user releases mouse
    hasSelection = true
    currentlySelecting = false
    

    I tried hooking into mousePressEvent/mouseReleaseEvent for the QPlainTextEdit, but mouseReleaseEvent doesn't get fired when another app takes focus and then the mouse is released, leaving me in a bad state. Is there a more reliable way to check whether the user is currently mouse-selecting text in a QPlainTextEdit?

    jsulmJ 1 Reply Last reply
    0
    • D Drew W

      I can get the cursor and check hasSelection(), but this only tells me if there is text selected. Not whether the user is currently in the process of selecting something. I would like something that evaluates to currentlySelecting:

      hasSelection = false
      currentlySelecting = false
      // user holds mouse button
      hasSelection = false
      currentlySelecting = false
      // user drags mouse to select text
      hasSelection = true
      currentlySelecting = true
      // user releases mouse
      hasSelection = true
      currentlySelecting = false
      

      I tried hooking into mousePressEvent/mouseReleaseEvent for the QPlainTextEdit, but mouseReleaseEvent doesn't get fired when another app takes focus and then the mouse is released, leaving me in a bad state. Is there a more reliable way to check whether the user is currently mouse-selecting text in a QPlainTextEdit?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Drew-W Maybe https://doc.qt.io/qt-5/qwidget.html#leaveEvent could help in the case other app gets focus?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved