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. [Solved] QListWidgetItem rename
QtWS25 Last Chance

[Solved] QListWidgetItem rename

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 9.6k Views
  • 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 Offline
    S Offline
    szh1
    wrote on last edited by
    #1

    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
    0
    • T Offline
      T Offline
      tony
      wrote on last edited by
      #2

      Well,

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

      T.

      1 Reply Last reply
      1
      • T Offline
        T Offline
        t3chNo
        wrote on last edited by
        #3

        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
        0
        • S Offline
          S Offline
          szh1
          wrote on last edited by
          #4

          Thanks, t3chNo.
          It works flawlessly.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            t3chNo
            wrote on last edited by
            #5

            Antonio's solution is better.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              szh1
              wrote on last edited by
              #6

              Why?

              1 Reply Last reply
              0
              • T Offline
                T Offline
                t3chNo
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tony
                  wrote on last edited by
                  #8

                  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
                  0

                  • Login

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