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 catch mouse click in QDoubleSpinbox
Forum Updated to NodeBB v4.3 + New Features

How to catch mouse click in QDoubleSpinbox

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 442 Views 2 Watching
  • 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.
  • M Offline
    M Offline
    MasterBlade
    wrote on last edited by
    #1

    Hello I have a QDoubleSpinbox and I want to make it so that when a user clicks its value, it automatically selects the value so the user can type a new value to it.

    I used the following event filter. But during my test, the function is only called when I click on the main framework (anywhere outside those spinboxes). What should I do?

    bool MainWindow::eventFilter(QObject* obj, QEvent* event)
    {
        if (event->type() == QEvent::MouseButtonPress){
            if (obj == ui->input){
                ui->input->selectAll();
                return true;
            }
            if (obj == ui->error){
                ui->error->selectAll();
                return true;
            }
        }
        return QObject::eventFilter(obj, event);
    }
    
    JonBJ 1 Reply Last reply
    0
    • M MasterBlade

      Hello I have a QDoubleSpinbox and I want to make it so that when a user clicks its value, it automatically selects the value so the user can type a new value to it.

      I used the following event filter. But during my test, the function is only called when I click on the main framework (anywhere outside those spinboxes). What should I do?

      bool MainWindow::eventFilter(QObject* obj, QEvent* event)
      {
          if (event->type() == QEvent::MouseButtonPress){
              if (obj == ui->input){
                  ui->input->selectAll();
                  return true;
              }
              if (obj == ui->error){
                  ui->error->selectAll();
                  return true;
              }
          }
          return QObject::eventFilter(obj, event);
      }
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @MasterBlade
      I don't know, but would it work if you sub-classed the QDoubleSpinbox and overrode its eventFilter() instead? You can have an eventFilter() on every QWidget (and then it is self-contained/standalone, does not rely on writing it in container), you don't have to have it on just your QMainWindow or whatever.

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        You likely want to apply that to the QLineEdit used in the QDoubleSpinBox. See the lineEdit method to get it.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

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