Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to disable mouseClick event!
Qt 6.12 LTS is out! See what's new in the release blog

How to disable mouseClick event!

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 2.8k 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.
  • M Offline
    M Offline
    MokJ
    wrote on last edited by MokJ
    #1

    I have created buttons using QItemDelegate for displaying them in a QListView , in which those buttons should be clickable, which is working too.
    But the problem is the rest of the part of the widget , I want it to do nothing if I click the rest of the area, is there a way !?

    raven-worxR 1 Reply Last reply
    0
    • M MokJ

      I have created buttons using QItemDelegate for displaying them in a QListView , in which those buttons should be clickable, which is working too.
      But the problem is the rest of the part of the widget , I want it to do nothing if I click the rest of the area, is there a way !?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @MokJ
      show how you created your delegate excatly

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      M 1 Reply Last reply
      1
      • raven-worxR raven-worx

        @MokJ
        show how you created your delegate excatly

        M Offline
        M Offline
        MokJ
        wrote on last edited by
        #3

        I am subclassing the QItemDelegate.

        void myDeligate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{
        
        // I'm creating a QRect and printing it as a button
        
         QRect ButtonRect(option.rect;);
         ButtonRect.setY(textRect.y()+35);
         ButtonRect.setHeight(30);
         QStyleOptionButton button;
            
            button.rect=ButtonRect;
            button.text=item->text();
            button.state=m_state|QStyle::State_Enabled;
        QApplication::style()->drawControl(QStyle::CE_PushButton,&button,painter);
        }
        QSize myDeligate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const{
        }
        bool myDeligate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index){
                    if(event->type()==QEvent::MouseButtonPress){
                                emit buttonClicked(index);
            }
        }
        
        

        I have connected

        emit buttonClicked(index);
        

        to an appropriate slot , Which does

        qDebug()<<"Clicked";
        

        And I'm receiving that message by clicking all over the widget.
        Thank you.

        raven-worxR 1 Reply Last reply
        0
        • M MokJ

          I am subclassing the QItemDelegate.

          void myDeligate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{
          
          // I'm creating a QRect and printing it as a button
          
           QRect ButtonRect(option.rect;);
           ButtonRect.setY(textRect.y()+35);
           ButtonRect.setHeight(30);
           QStyleOptionButton button;
              
              button.rect=ButtonRect;
              button.text=item->text();
              button.state=m_state|QStyle::State_Enabled;
          QApplication::style()->drawControl(QStyle::CE_PushButton,&button,painter);
          }
          QSize myDeligate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const{
          }
          bool myDeligate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index){
                      if(event->type()==QEvent::MouseButtonPress){
                                  emit buttonClicked(index);
              }
          }
          
          

          I have connected

          emit buttonClicked(index);
          

          to an appropriate slot , Which does

          qDebug()<<"Clicked";
          

          And I'm receiving that message by clicking all over the widget.
          Thank you.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @MokJ:
          of course. You accept any mouse press event in the widget, no matter where it appeared.

          bool myDeligate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index){
                      if(event->type()==QEvent::MouseButtonPress ) {
                                  QMouseEvent* me = static_cast<QMouseEvent*>(event);
                                  if( option.rect.contains(me->pos()) )
                                        emit buttonClicked(index);
              }
          }
          

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          4
          • M Offline
            M Offline
            MokJ
            wrote on last edited by MokJ
            #5

            @raven-worx Thanks for responding , The problem is solved.
            I had to handle the QMouseEvent properly.

            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
            • Unsolved