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. get mousePressEvent in qlistview

get mousePressEvent in qlistview

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 4 Posters 4.6k 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.
  • mrjjM mrjj

    Hi
    The viewport do not have a clicked() signal.
    I meant for you use it with event filter to catch it that way.

    S Offline
    S Offline
    saber
    wrote on last edited by
    #10

    @mrjj i am getting mousePressEvent in outside of listview

    0_1525099082598_uu.png

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #11

      Hmm, it dont recall it being that difficult.
      And the listview is all the way down there ?

      S 1 Reply Last reply
      0
      • mrjjM mrjj

        Hmm, it dont recall it being that difficult.
        And the listview is all the way down there ?

        S Offline
        S Offline
        saber
        wrote on last edited by saber
        #12

        @mrjj
        no, that is another widget.
        i need that function . please help me

        mrjjM 1 Reply Last reply
        0
        • S saber

          @mrjj
          no, that is another widget.
          i need that function . please help me

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #13

          @saber
          Well what ever widget is under the mouse cursor gets the click.
          So you need event filter on those too.
          I though you just want to click outside the actual items,
          not the whole wide window.

          S 1 Reply Last reply
          0
          • mrjjM mrjj

            @saber
            Well what ever widget is under the mouse cursor gets the click.
            So you need event filter on those too.
            I though you just want to click outside the actual items,
            not the whole wide window.

            S Offline
            S Offline
            saber
            wrote on last edited by saber
            #14

            @mrjj
            yes , i just want to click outside the actual items in listview .
            i just want click event on list view .
            not whole window.

            0_1525160332219_Screenshot_2018-05-01_13-34-34.png

            but mouse press event not working there.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              saber
              wrote on last edited by
              #15

              any light ?

              1 Reply Last reply
              0
              • VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by VRonin
                #16

                Try this:

                class ClickOutListView : public QListView{
                Q_OBJECT
                Q_DISABLE_COPY(ClickOutListView)
                public:
                explicit ClickOutListView(QWidget* parent = Q_NULLPTR) : QListView(parent){}
                Q_SIGNALS:
                void clickedOut();
                protected:
                void mousePressEvent(QMouseEvent *event){
                if(!indexAt(event->pos()).isValid()) 
                clickedOut();
                QListView::mousePressEvent(event);
                }
                };
                

                and right-click->promote your QListView to ClickOutListView in designer

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                S 1 Reply Last reply
                4
                • VRoninV VRonin

                  Try this:

                  class ClickOutListView : public QListView{
                  Q_OBJECT
                  Q_DISABLE_COPY(ClickOutListView)
                  public:
                  explicit ClickOutListView(QWidget* parent = Q_NULLPTR) : QListView(parent){}
                  Q_SIGNALS:
                  void clickedOut();
                  protected:
                  void mousePressEvent(QMouseEvent *event){
                  if(!indexAt(event->pos()).isValid()) 
                  clickedOut();
                  QListView::mousePressEvent(event);
                  }
                  };
                  

                  and right-click->promote your QListView to ClickOutListView in designer

                  S Offline
                  S Offline
                  saber
                  wrote on last edited by
                  #17

                  @VRonin
                  sorry for late reply .
                  your code is working.
                  can i use this in treewidget to achieve same mouseevent?

                  mrjjM 1 Reply Last reply
                  0
                  • S saber

                    @VRonin
                    sorry for late reply .
                    your code is working.
                    can i use this in treewidget to achieve same mouseevent?

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #18

                    @saber
                    Hi
                    Yes QTreeWidget also have
                    mousePressEvent etc. so should work the same.

                    S 1 Reply Last reply
                    1
                    • mrjjM mrjj

                      @saber
                      Hi
                      Yes QTreeWidget also have
                      mousePressEvent etc. so should work the same.

                      S Offline
                      S Offline
                      saber
                      wrote on last edited by
                      #19

                      @mrjj

                      in treeview it's also working.
                      thanks.

                      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