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 indicator
Qt 6.11 is out! See what's new in the release blog

QLineEdit indicator

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 3.8k Views 3 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.
  • G Offline
    G Offline
    GrahamL
    wrote on last edited by
    #1

    Hi
    I would like to have an indicator associated with a qlineedit to show when a field on a form has been edited.(similar to the clear button functionality)
    Has anyone any suggestions as to how this can be done?

    Thanks

    1 Reply Last reply
    0
    • TheBadgerT Offline
      TheBadgerT Offline
      TheBadger
      wrote on last edited by
      #2

      I would suggest to change the stylesheet to perhaps change the color when the user edits the text and clears it when submitted:

          QWidget* myWidget = new QWidget(nullptr);
          QVBoxLayout *vboxLayout = new QVBoxLayout(myWidget);
          QLineEdit* edit = new QLineEdit("Test");
          connect(edit, &QLineEdit::textChanged, [edit]{edit->setStyleSheet("background-color: yellow");});
          QPushButton* submitButton = new QPushButton("Submit");
          connect(submitButton, &QPushButton::clicked, [edit]{edit->setStyleSheet(""); });
          vboxLayout->addWidget(edit);
          vboxLayout->addWidget(submitButton);
          myWidget->show();
      

      The above code is a very simple example to show the idea. But you can update as you need to.


      Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GrahamL
        wrote on last edited by
        #3

        Thanks - something to think about

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          A less manual solution is to add an action to the line edit using addAction(). Then you can just change the action's icon to indicate the state.

          G 1 Reply Last reply
          0
          • Chris KawaC Chris Kawa

            A less manual solution is to add an action to the line edit using addAction(). Then you can just change the action's icon to indicate the state.

            G Offline
            G Offline
            GrahamL
            wrote on last edited by
            #5

            @Chris-Kawa
            Hi
            I have tried this but the icon does not show up

            	m_action = new QAction(this);
            
            	QIcon icon(":/cross.png");
            	m_action->setIcon(icon);
            
            	ui->nameEdit->addAction(m_action);
            
            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Should be something like:

               QIcon icon(":/cross.png");
               m_action = ui->nameEdit->addAction(icon, QLineEdit::TrailingPosition);
              
              1 Reply Last reply
              1
              • G Offline
                G Offline
                GrahamL
                wrote on last edited by
                #7

                Thanks got it now

                1 Reply Last reply
                0

                • Login

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