Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    [Solved] QListWidgetItem rename

    General and Desktop
    3
    8
    8739
    Loading More Posts
    • 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.
    • S
      szh1 last edited by

      I have a QListWidget that the user populates with QListWidgetItems. The user can double-click the list item to rename it. I would like to programmatically put the list item in that 'renaming state', like when you press F2 in Windows Explorer with a file selected. How can I accomplish this?

      1 Reply Last reply Reply Quote 0
      • T
        tony last edited by

        Well,

        if you want to reproduce Explorer behavior, you should set QAbstractItemView::SelectedClicked and QAbstractItemView::EditKeyPressed with setEditTriggers method.

        T.

        1 Reply Last reply Reply Quote 1
        • T
          t3chNo last edited by

          First, make QListWidgetItems editable. You can do it by setting Qt::ItemIsEditable flag. Then connect listWidgets itemClicked signal to your slot that changes item state to edit. ( QListWidget::editItem( QListWidgetItem* ) ) Afaik, for F12, you have to install event filter to listwidget or create custom listwidget.

          1 Reply Last reply Reply Quote 0
          • S
            szh1 last edited by

            Thanks, t3chNo.
            It works flawlessly.

            1 Reply Last reply Reply Quote 0
            • T
              t3chNo last edited by

              Antonio's solution is better.

              1 Reply Last reply Reply Quote 0
              • S
                szh1 last edited by

                Why?

                1 Reply Last reply Reply Quote 0
                • T
                  t3chNo last edited by

                  QListWidget internally supports your needs. You don't need to code much. Code less, create more :)

                  1 Reply Last reply Reply Quote 0
                  • T
                    tony last edited by

                    t3chNo is right, this is the main philosophy :)

                    Joking aside, I guess that everybody's right, the point of view is different.

                    Mine is: "Ok, assume that the item is editable ... which are the input keys (mouse or keyboard) that are allowed to enter in edit mode??" ... and these should be set.

                    t3chNo is: "You should tell me if the single item is editable or not".

                    Of course, if the default flags() allows editing, mine is the straightforward solution. Otherwise, you should do both.

                    T.

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post