Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. PySide find out last clicked QLineEdit
Forum Updated to NodeBB v4.3 + New Features

PySide find out last clicked QLineEdit

Scheduled Pinned Locked Moved Unsolved Qt for Python
qt for pythonpythonpysidepyside2
5 Posts 2 Posters 954 Views
  • 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 Offline
    T Offline
    To RGB
    wrote on last edited by To RGB
    #1

    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!

    JonBJ 1 Reply Last reply
    0
    • T 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!

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @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
      0
      • JonBJ 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 Offline
        T Offline
        To RGB
        wrote on last edited by
        #3

        @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.

        JonBJ 1 Reply Last reply
        0
        • T To RGB

          @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.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @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
          1
          • JonBJ 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 Offline
            T Offline
            To RGB
            wrote on last edited by To RGB
            #5

            @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
            1

            • Login

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