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. MousePressEvent ( QMouseEvent * event ) in subclass of QSpinbox getting called only when cursor on up down arrow
Forum Updated to NodeBB v4.3 + New Features

MousePressEvent ( QMouseEvent * event ) in subclass of QSpinbox getting called only when cursor on up down arrow

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 7.0k Views 1 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.
  • Y Offline
    Y Offline
    yanbellavance
    wrote on last edited by
    #1

    I am trying to re-implement the mousePressEvent in a sub class of QSpinBox but it only gets called when the mouse interacts with the up and down arrows of the spinbox. Is there a way I can get around this? Perhaps and event filter...gonna look into that.

    here is my header:
    @#ifndef WVSPINBOXMSNEDIT_H
    #define WVSPINBOXMSNEDIT_H

    #include <QWidget>
    #include <QObject>
    #include <QSpinBox>
    #include <QEvent>
    #include <QMouseEvent>

    class wvSpinBoxMsnEdit : public QSpinBox
    {
    Q_OBJECT

    public:
    explicit wvSpinBoxMsnEdit(QWidget *parent = 0);

    protected:
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);

    public:
    bool msnEdit;

    };

    #endif // WVSPINBOXMSNEDIT_H
    @

    and here is my cpp:

    @#include "wvspinboxmsnedit.h"

    wvSpinBoxMsnEdit::wvSpinBoxMsnEdit(QWidget *parent) :
    QSpinBox(parent)
    {
    msnEdit=false;
    }
    void wvSpinBoxMsnEdit::mousePressEvent ( QMouseEvent * event ){
    msnEdit=true;
    QAbstractSpinBox::mousePressEvent(event);
    event->accept();
    }

    void wvSpinBoxMsnEdit::mouseReleaseEvent ( QMouseEvent * event ){
    msnEdit=true;
    QAbstractSpinBox::mouseReleaseEvent(event);
    event->accept();
    }
    @

    thanks

    1 Reply Last reply
    0
    • BilbonSacquetB Offline
      BilbonSacquetB Offline
      BilbonSacquet
      wrote on last edited by
      #2

      Of course a QSpinBox widget is a composition of widgets, in fact 2 widgets the spinbox and it's child the line edit) and the rule is that the upper widget get the mouse event.

      In case of the spinbox it's the text line widget which takes them. The buttons in contrario aren't child widgets it's just a graphical part of the spinbox. it's rendered by the style (QXxxStyle).

      To resume if you go on text edit the mouse messages go to it, other areas it is its parent - the combobox which gets them.

      Now of course you should install an event filter to the line edit but it sound all like an hack, rethink more on the way you will implement and probably there is another to handle your problem without to take the mouse events!

      1 Reply Last reply
      0

      • Login

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