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. SetFocus on widget in a new
Qt 6.11 is out! See what's new in the release blog

SetFocus on widget in a new

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 30.6k 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.
  • A Offline
    A Offline
    abibiano
    wrote on last edited by
    #1

    I have a main window with a QListWidget as menu and a QTabWidget as my main area.

    When I click on a menu item on the listwidget I create my form and add it to the tabwidget.

    This is the code used:

    @void MainWindow::openFormCateries()
    {
    if(m_formCategories == 0)
    {
    m_formCategories = new FormCategories(this);
    ui->tabWidget->addTab(m_formCategories, tr("Categories"));

    }
    ui->tabWidget->setCurrentWidget (m_formCategories);
    

    }@

    My problem is that I don't know how to set the focus on the first editable item from the new created form added to the tab.

    I have for example a QLineEdit in m_formCategories and want to set it as the active control.

    I have tried set the focus on the constructor from m_formCategories whith ui->lineedit1->setfocus() but it dosen't work.

    Thanks,

    Alex B.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mohsen
      wrote on last edited by
      #2

      @QWidget obj = (QWidget)m_formCategories->children().at(0);
      obj->setFocus();@

      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