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. QLineEdit disable action click

QLineEdit disable action click

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 3.6k 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.
  • M Offline
    M Offline
    Mr Gisa
    wrote on last edited by
    #1

    I added an icon to a QLineEdit using the addAction method but I was wondering how to remove the click behavior?
    I tried to use setEnabled(false) to the action but it turns the icon gray.

    0_1526952279827_6ae1489b-6ae7-442d-bb42-14505f49dccf-image.png

    disabled:

    0_1526952314357_7afd9105-49b7-4e58-885e-91776546ec46-image.png

    A 1 Reply Last reply
    0
    • M Mr Gisa

      I added an icon to a QLineEdit using the addAction method but I was wondering how to remove the click behavior?
      I tried to use setEnabled(false) to the action but it turns the icon gray.

      0_1526952279827_6ae1489b-6ae7-442d-bb42-14505f49dccf-image.png

      disabled:

      0_1526952314357_7afd9105-49b7-4e58-885e-91776546ec46-image.png

      A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      @Mr-Gisa What do you mean by "click behavior"? What's the point of the button if you can't click it?

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mr Gisa
        wrote on last edited by Mr Gisa
        #3

        It's not a button, it's a QAction. If you put an QAction in a QLineEdit you can click on it, I want to disable the click behavior as it is when you use setEnabled(false) the problem is that it turns gray.

        A 1 Reply Last reply
        0
        • M Mr Gisa

          It's not a button, it's a QAction. If you put an QAction in a QLineEdit you can click on it, I want to disable the click behavior as it is when you use setEnabled(false) the problem is that it turns gray.

          A Offline
          A Offline
          ambershark
          wrote on last edited by
          #4

          @Mr-Gisa Still not understanding... Do you just want the icon or do you want the actual qaction? If you want the action why would you not want it to be clickable? And if it was temporarily not clickable then setEnabled(false) is the right way to do it so it grays out so the user knows it is non-usable.

          I think I'm just confused as to what you're trying to accomplish though.

          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mr Gisa
            wrote on last edited by
            #5

            I want to put the icon in the QLineEdit that is the easiest way I found to do that, but it comes with the click behavior due to QAction and so I want to remove that behavior

            A 2 Replies Last reply
            0
            • M Mr Gisa

              I want to put the icon in the QLineEdit that is the easiest way I found to do that, but it comes with the click behavior due to QAction and so I want to remove that behavior

              A Offline
              A Offline
              ambershark
              wrote on last edited by
              #6

              @Mr-Gisa Ok so it's just for the icon ... I'll play with it for a minute and see if I can get a fix for you.

              My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

              1 Reply Last reply
              0
              • M Mr Gisa

                I want to put the icon in the QLineEdit that is the easiest way I found to do that, but it comes with the click behavior due to QAction and so I want to remove that behavior

                A Offline
                A Offline
                ambershark
                wrote on last edited by
                #7

                @Mr-Gisa Are you using a QAction that is linked to an actual clickable action? When I did it, mine doesn't process clicks.

                Here's how it looks:

                0_1526960520317_Screenshot from 2018-05-21 20-41-22.png

                And it's not clickable. I mean it is but it doesn't show that it was clicked and it doesn't do anything.

                Code:

                TestDialog::TestDialog(QWidget *parent)
                    : QWidget(parent)
                {
                    resize(400, 150);
                    
                    act_ = new QAction();
                    act_->setIcon(QIcon("/usr/share/pixmaps/nobody.png"));
                    
                    auto le = new QLineEdit(this);
                    le->setClearButtonEnabled(true);
                    le->addAction(act_, QLineEdit::LeadingPosition);
                    le->setPlaceholderText("User...");
                    
                    auto layout = new QHBoxLayout();
                    layout->addWidget(le);
                    setLayout(layout);
                }
                

                My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                M 1 Reply Last reply
                0
                • A ambershark

                  @Mr-Gisa Are you using a QAction that is linked to an actual clickable action? When I did it, mine doesn't process clicks.

                  Here's how it looks:

                  0_1526960520317_Screenshot from 2018-05-21 20-41-22.png

                  And it's not clickable. I mean it is but it doesn't show that it was clicked and it doesn't do anything.

                  Code:

                  TestDialog::TestDialog(QWidget *parent)
                      : QWidget(parent)
                  {
                      resize(400, 150);
                      
                      act_ = new QAction();
                      act_->setIcon(QIcon("/usr/share/pixmaps/nobody.png"));
                      
                      auto le = new QLineEdit(this);
                      le->setClearButtonEnabled(true);
                      le->addAction(act_, QLineEdit::LeadingPosition);
                      le->setPlaceholderText("User...");
                      
                      auto layout = new QHBoxLayout();
                      layout->addWidget(le);
                      setLayout(layout);
                  }
                  
                  M Offline
                  M Offline
                  Mr Gisa
                  wrote on last edited by Mr Gisa
                  #8

                  @ambershark I'm on Windows and when you press the icon it behaves like it's an actual button (the effect), It's weird cause it feels like an unfinished feature or some bug (user point of view).

                  A 2 Replies Last reply
                  0
                  • M Mr Gisa

                    @ambershark I'm on Windows and when you press the icon it behaves like it's an actual button (the effect), It's weird cause it feels like an unfinished feature or some bug (user point of view).

                    A Offline
                    A Offline
                    ambershark
                    wrote on last edited by
                    #9

                    @Mr-Gisa Windows?! Yuck! :P Let me see if I add an action if it clicks or not. Then if I can make it "click" I can help find a way to stop it. I have some ideas but I need to test them before I tell you about them.

                    My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                    1 Reply Last reply
                    0
                    • M Mr Gisa

                      @ambershark I'm on Windows and when you press the icon it behaves like it's an actual button (the effect), It's weird cause it feels like an unfinished feature or some bug (user point of view).

                      A Offline
                      A Offline
                      ambershark
                      wrote on last edited by ambershark
                      #10

                      @Mr-Gisa Ok played with it a little bit ... linux doesn't show the clicks like windows apparently does. I don't have easy access to my Windows vm with qt in it to test right now.

                      There is no easy way to disable the click behavior. Here are some ideas:

                      1. You can write a custom class derived from QAction, then ignore clicks. That would be a pain though.
                      2. You could write a custom QLineEdit that draws the image (should be fairly easy, but still some work).
                      3. You could use a style sheet on the QLineEdit that loads the image and puts it as a left aligned non-repeating background image. No guarantees this would work, but it should.
                      4. You could switch your gui to QML where stuff like this is super easy. This isn't a serious recommendation, but if you find you want custom GUIs a lot then QML is definitely the better choice for designing them. Or you end up writing a lot of custom widgets.
                      5. You could just ignore the click behavior windows does
                      6. Or you could assign the click to do something like focus and select all in the line edit. That would feel natural and explain the "click".

                      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                      1 Reply Last reply
                      2
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        Hi,

                        This stack overflow thread provides several possible way of doing it that could be of interest.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        3

                        • Login

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