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. hasFocus() ??
Forum Updated to NodeBB v4.3 + New Features

hasFocus() ??

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 907 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.
  • D Offline
    D Offline
    Duy Khang
    wrote on last edited by
    #1

    how to check a lineEdit or a pushButton has focus ? ();
    i used ui->lineEdit_username->hasFocus(), but it does'n work .
    someone cans tell me why ?

    JonBJ 1 Reply Last reply
    0
    • D Duy Khang

      how to check a lineEdit or a pushButton has focus ? ();
      i used ui->lineEdit_username->hasFocus(), but it does'n work .
      someone cans tell me why ?

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

      @Duy-Khang said in hasFocus() ??:

      but it does'n work .

      Well, I would imagine it does work, else others would complain?! How does your situation compare to, say, https://stackoverflow.com/questions/46702487/how-can-i-get-current-focused-qlineedit-in-qt ?

      1 Reply Last reply
      1
      • D Offline
        D Offline
        Duy Khang
        wrote on last edited by
        #3

        @JonB said in hasFocus() ??:

        Well, I would imagine it does work, else others would complain?! How does your situation compare to, say

        not like that. suppuse :
        ui->lineEdit_username->setFocus();
        if(ui->lineEdit_username->hasFocus())
        {
        ui->lineEdit_username->setStyleSheet("color : red"); // it still doesn't work ?
        }

        JonBJ 1 Reply Last reply
        0
        • D Duy Khang

          @JonB said in hasFocus() ??:

          Well, I would imagine it does work, else others would complain?! How does your situation compare to, say

          not like that. suppuse :
          ui->lineEdit_username->setFocus();
          if(ui->lineEdit_username->hasFocus())
          {
          ui->lineEdit_username->setStyleSheet("color : red"); // it still doesn't work ?
          }

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

          @Duy-Khang
          Please just put in

          if(ui->lineEdit_username->hasFocus())
              qDebug() << "Yes has focus";
          
          1 Reply Last reply
          1
          • D Offline
            D Offline
            Duy Khang
            wrote on last edited by
            #5

            it stil does not work !

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

              Hi
              Useing code to check for fucus will work poorly if used in constructor and code must be run every time
              focus shifts so it's easier to do with stylesheet alone.

              QLineEdit:focus {
              color:red;
              }
              

              alt text

              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