Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Unsolved PySide find out last clicked QLineEdit

    Qt for Python
    qt for python python pyside pyside2
    2
    5
    346
    Loading More Posts
    • 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.
    • T
      To RGB last edited by To RGB

      Hi! I'm new to PySide and this is my first complex project.
      I have main widget (inherited from QWidget, not QMainWindow), where are three widgets. Two custom QLineEdit widgets in separate *.py files and one QItemList in main widget.

      This is what I want to do:
      There are some text Items in ItemList and I want to click on first or second LineEdit and then click on the Items. Items that were clicked must be added to first or second LineEdit, depending on what was selected last.

      The problem is that I can't get information what LineEdit was selected last. I tried to use hasFocus() function, but it always return false, because it become false after I click on the Item. Also I tried to use mousePressEvent in custom LineEdit widget, this way I can track what LineEdit was clicked, but I can't use this info either, because I don't know how to send it to QListWidget in main window. Only solution that I found is to use *.json file and save there what LineEdit was clicked last and then use this info in method in main widget. But I'm sure there is a correct way to do it. I'd be glad for any help, thanks!

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @To RGB last edited by JonB

        @To-RGB
        To achieve this, simplest for you is: define two slots for QLineEdit::clicked, in each one set some outside variable (probably a member variable of the containingQWidget) to the corresponding QLineEdit whose clicked signal you will attach to that slot. So now you know which one was last clicked. Use that for whatever you want to do in your item list.

        There are other ways of doing this --- including using a Python lambda to avoid having to write two separate slots --- but for just 2 this is the simplest as a newbie.

        T 1 Reply Last reply Reply Quote 0
        • T
          To RGB @JonB last edited by

          @JonB , thanks for the answer! If I understood it correctly, do you mean to use clicked() signal? I tried to find it in documentation, but unfortunately QLineEdit has not clicked() signal, that's why I created custom LineEdit and tried to do something with mousePressEvent.

          JonB 1 Reply Last reply Reply Quote 0
          • JonB
            JonB @To RGB last edited by JonB

            @To-RGB
            You are right, I assumed it had a clicked signal :) You could use any of the suggestions from e.g. https://stackoverflow.com/questions/6452077/how-to-get-click-event-of-qlineedit-in-qt.

            Whatever you use --- whether subclassing, event filter, whatever --- the principle still remains that you will need to save up which line edit (e.g. if you subclass that would be self in the event) was "clicked" in some persistent variable, and use that later when user interacts with your QItemList. Can I leave it to you?

            T 1 Reply Last reply Reply Quote 1
            • T
              To RGB @JonB last edited by To RGB

              @JonB argh! I spend a whole day yesterday to figure out how to make it work, and all I needed to do is to write mySignal=Signal() not in the init, but in the class body! Jeeeez.
              Thanks a lot! Your advices and link helped!

              1 Reply Last reply Reply Quote 1
              • First post
                Last post