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. Setting focus in text box
Forum Updated to NodeBB v4.3 + New Features

Setting focus in text box

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 4.2k 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.
  • J Offline
    J Offline
    joeydonovan4
    wrote on last edited by
    #1

    I have a text box and when I hover the mouse over it, it accepts keyboard focus. I want the text box to only accept keyboard focus when it is clicked, and not when it is hovered over. How do I do this? I am using: widget->setFocusPolicy(Qt::ClickFocus) but it doesn't seem to be affecting anything.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      By default it is click focus only. Do you have sample code ? I tried with 3 different text boxes. TextBoxes get focus when I click on them.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      J 1 Reply Last reply
      4
      • dheerendraD dheerendra

        By default it is click focus only. Do you have sample code ? I tried with 3 different text boxes. TextBoxes get focus when I click on them.

        J Offline
        J Offline
        joeydonovan4
        wrote on last edited by
        #3

        @dheerendra

        QWidget* widget = (QWidget*)field->id;
        widget->setFocusPolicy(Qt::ClickFocus);

        id is a handle to the text box

        1 Reply Last reply
        0
        • R Offline
          R Offline
          root0x
          wrote on last edited by
          #4

          The way i do it is ui->textbox->setFocus();

          J 1 Reply Last reply
          0
          • R root0x

            The way i do it is ui->textbox->setFocus();

            J Offline
            J Offline
            joeydonovan4
            wrote on last edited by
            #5

            @root0x I'm new to this so help me out. What is ui a pointer to? And is 'textbox' replacing 'widget' in this case?

            J 1 Reply Last reply
            0
            • J joeydonovan4

              @root0x I'm new to this so help me out. What is ui a pointer to? And is 'textbox' replacing 'widget' in this case?

              J Offline
              J Offline
              jalomic
              wrote on last edited by
              #6

              @joeydonovan4 "ui " - it is pointer to auto-generated UI from UI-designer ( If you using UI-designer )

              Can you post some more code ?

              1 Reply Last reply
              0
              • R Offline
                R Offline
                root0x
                wrote on last edited by
                #7

                textbox is just the widget name

                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