×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    49

    QWidget: StrongFocus and mousePressEvent

    Hello,

    Environment:
    Win7, Qt 4.6.3, E51/E71/Samsung i8910

    I have a window with multiple custom widgets in QGridLayout. Each widget consists of several fields (e.g. QLineEdit or QLabel) with FocusPolicy set to Qt::NoFocus. The parent widgets FocusPolicy is set to Qt::StrongFocus.

    On Nokia E51 and E71 I'm able to select a widget by using the navigation button. However, if I click the widget nothing happens. I'm unable to catch the mousePressEvent. On the other hand, if I compile the code for Windows 7 or use phone with a touch screen the event is raised and everything works fine.

    code example:

    .h
    Code:
    class MyWidget : public QWidget
    {
    Q_OBJECT
    public:
        explicit MyWidget(QWidget *parent = 0);
    
    private:
        QLabel *m_Title;
        QLineEdit *m_Value;
    
    protected:
        void mousePressEvent(QMouseEvent *event);
    
    public slots:
        void OnClicked();
    };
    .cpp
    Code:
    MyWidget::MyWidget(QWidget *parent) :
        QWidget(parent)
    {
        m_Title = new QLabel("test", this);
        m_Value = new QLineEdit(this);
    
        Initialize();
    }
    
    void MdSettingBox::Initialize()
    {
        // layout items
        QGridLayout *layout = new QGridLayout(this);
    
        // focus policy
        m_Value->setFocusPolicy(Qt::NoFocus);
        m_Title->setFocusPolicy(Qt::NoFocus);
        setFocusPolicy(Qt::StrongFocus);
    
        // add items to layout
        layout->addWidget(m_Title, 0, 0, Qt::AlignLeft);
        layout->addWidget(m_Value, 1, 0, Qt::AlignRight);
    }
    
    void MdSettingBox::mousePressEvent(QMouseEvent *event)
    {
        OnClicked();
    }
    Is there any way to implement the mousePressEvent with StrongFocus on older devices?

  2. #2
    Super Contributor
    Join Date
    Oct 2008
    Location
    INDIA
    Posts
    2,326

    Re: QWidget: StrongFocus and mousePressEvent

    If your project contains click event then, go to the below article in which how the control transfer using mouse arrow keys.

    http://wiki.forum.nokia.com/index.ph...Qt_for_Symbian

    Cheers,

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    49

    Re: QWidget: StrongFocus and mousePressEvent

    Hello rahulvala,

    currently my project does not contain the click event (because Widget does not have it.). That article did not provide any help.

    I'm trying to make the widget behave like a button and therefore I'm using the mousePressEvent. The behavior I'm looking is similar with default S60 3.1 settings views (e.g. Settings->General->Personalisation->Display. ).

  4. #4
    Nokia Developer Moderator
    Join Date
    Mar 2009
    Posts
    1,024

    Re: QWidget: StrongFocus and mousePressEvent

    Quote Originally Posted by Tuomo View Post
    Hello rahulvala,

    currently my project does not contain the click event (because Widget does not have it.). That article did not provide any help.

    I'm trying to make the widget behave like a button and therefore I'm using the mousePressEvent. The behavior I'm looking is similar with default S60 3.1 settings views (e.g. Settings->General->Personalisation->Display. ).
    Mouse events are usually generated by a pointer (mouse or touchscreen)... E51 and E71 don't send any mouse event.

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    49

    Re: QWidget: StrongFocus and mousePressEvent

    Quote Originally Posted by gnuton View Post
    Mouse events are usually generated by a pointer (mouse or touchscreen)... E51 and E71 don't send any mouse event.
    Thanks for the reply, that explains the behavior.

    To the original question, is there any way to detect "clicked" signal on QWidget if mousePressEvent can't be used?

  6. #6
    Nokia Developer Moderator
    Join Date
    Mar 2009
    Posts
    1,024

    Re: QWidget: StrongFocus and mousePressEvent

    Quote Originally Posted by Tuomo View Post
    Thanks for the reply, that explains the behavior.

    To the original question, is there any way to detect "clicked" signal on QWidget if mousePressEvent can't be used?
    You can generate Mouse events as well as any event supported by Qt.. with some limitations in some cases. For instance MouseEvents generated by X11 server on Linux (desktop or Maemo) contain data related to the native XEvents.
    "Native" events are usually called "spontaneous". Check QEvent::spontaneous () for more info.

    Anyway the code should look like this:
    QMouseEvent e = new QMouseEvent(...);
    QCoreApplication:: postEvent(my_object, e);

  7. #7
    Registered User
    Join Date
    Mar 2010
    Posts
    49

    Re: QWidget: StrongFocus and mousePressEvent

    Quote Originally Posted by gnuton View Post
    You can generate Mouse events as well as any event supported by Qt.. with some limitations in some cases. For instance MouseEvents generated by X11 server on Linux (desktop or Maemo) contain data related to the native XEvents.
    "Native" events are usually called "spontaneous". Check QEvent::spontaneous () for more info.

    Anyway the code should look like this:
    QMouseEvent e = new QMouseEvent(...);
    QCoreApplication:: postEvent(my_object, e);
    Thanks again.

    That explains how to generate an event but it still requires another event/signal to trigger it? As I told before I'm able to gain the focus when moving on the widget, but I'm unable to detect user clicking on that widget.

  8. #8
    Nokia Developer Moderator
    Join Date
    Mar 2009
    Posts
    1,024

    Re: QWidget: StrongFocus and mousePressEvent

    Quote Originally Posted by Tuomo View Post
    Thanks again.

    That explains how to generate an event but it still requires another event/signal to trigger it? As I told before I'm able to gain the focus when moving on the widget, but I'm unable to detect user clicking on that widget.
    You can filter the QFocusEvents. Take a look at http://doc.trolltech.com/4.6/qobject...allEventFilter.
    Note you need just one filter method MyWidget::eventFilter(QObject *obj, QEvent *event) to filter all children widgets.

Similar Threads

  1. Crash in QWidget destruction - Help
    By amol.mahesh@gmail.com in forum Qt
    Replies: 31
    Last Post: 2010-07-31, 20:22
  2. TouchInput in a QWidget
    By hamzeeco in forum Qt
    Replies: 8
    Last Post: 2010-04-09, 21:44
  3. QWidget in QListWidgetItem off-center
    By danhicksbyron in forum Qt
    Replies: 4
    Last Post: 2010-03-18, 16:24

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •