Results 1 to 8 of 8

Thread: QListView bad behavior on rename

  1. #1
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QListView bad behavior on rename

    Hi all,
    I use a QListView using a QFileSystemModel to show folders, I set it not read only to have rename.
    That works but the problem is you can double click the icon to rename not only the name.
    Is it a way to have it working only on name of item ?
    I want double click on icon to be enter in folder.
    Thanks for the help

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListView bad behavior on rename

    Subclass the delegate and reimplement its editorEvent to only bypass the event to the base implementation if mouse press occured on the label.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Alundra (8th June 2014)

  4. #3
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QListView bad behavior on rename

    I tried long time to have working but I don't have the correct rect test working :
    Qt Code:
    1. class CItemDelegate : public QItemDelegate
    2. {
    3. public:
    4.  
    5. CItemDelegate( QObject* Parent ) :
    6. QItemDelegate( Parent )
    7. {
    8. }
    9.  
    10. virtual bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
    11. {
    12. if( event->type() == QEvent::MouseButtonDblClick )
    13. {
    14. QMouseEvent* MouseEvent = static_cast< QMouseEvent* >( event );
    15. if( option.rect.contains( MouseEvent->globalPos() ) == false )
    16. return QAbstractItemDelegate::editorEvent( event, model, option, index );
    17. }
    18. return QItemDelegate::editorEvent( event, model, option, index );
    19. }
    20. };
    To copy to clipboard, switch view to plain text mode 
    Hope you can help me

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListView bad behavior on rename

    Take a look at the delegate's source code to see how it calculates the rectangle for drawing the text.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QListView bad behavior on rename

    I'm afraid that doesn't work :
    Qt Code:
    1. virtual bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
    2. {
    3. if( event->type() == QEvent::MouseButtonDblClick )
    4. {
    5. QMouseEvent* MouseEvent = static_cast< QMouseEvent* >( event );
    6. const QRect TextRect = textRectangle( NULL, option.rect, option.font, option.text );
    7. if( TextRect.contains( MouseEvent->globalPos() ) == false )
    8. return QAbstractItemDelegate::editorEvent( event, model, option, index );
    9. }
    10. return QItemDelegate::editorEvent( event, model, option, index );
    11. }
    To copy to clipboard, switch view to plain text mode 
    Is it possible to have this action working in the doubleClicked signal of the QListView ?
    Because I have the doubleClicked action who do something in my tree and that bypass the delegate action.
    That mean have that to bypass the double click of delegate :
    Qt Code:
    1. class CItemDelegate : public QItemDelegate
    2. {
    3. public:
    4.  
    5. CItemDelegate( QObject* Parent ) :
    6. QItemDelegate( Parent )
    7. {
    8. }
    9.  
    10. virtual bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
    11. {
    12. if( event->type() == QEvent::MouseButtonDblClick )
    13. return true;
    14. return QItemDelegate::editorEvent( event, model, option, index );
    15. }
    16. };
    To copy to clipboard, switch view to plain text mode 
    Thanks for the help
    Last edited by Alundra; 8th June 2014 at 18:17.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListView bad behavior on rename

    What exactly "doesn't work"? How does "doesn't work" manifest itself?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QListView bad behavior on rename

    I can double click on the icon and text to rename :/
    Is it more correct to do all in delegate and not using the double click signal ?
    Qt Code:
    1. void CContentBrowserWidget::DetailDoubleClicked( const QModelIndex& index )
    2. {
    3. CFileSystemModel* ListModel = static_cast< CFileSystemModel* >( m_ListTree->model() );
    4. QFileSystemModel* DetailModel = static_cast< QFileSystemModel* >( m_DetailList->model() );
    5. const QString Path = DetailModel->filePath( index );
    6. const QFileInfo FileInfo( Path );
    7. if( FileInfo.isDir() )
    8. m_ListTree->setCurrentIndex( ListModel->index( Path ) );
    9. }
    To copy to clipboard, switch view to plain text mode 
    To bypass the rename on double click of a QTreeView I only found this way, this one works good :
    Qt Code:
    1. virtual bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
    2. {
    3. if( event->type() == QEvent::MouseButtonDblClick )
    4. {
    5. m_TreeView->expand( index );
    6. return true;
    7. }
    8. return QItemDelegate::editorEvent( event, model, option, index );
    9. }
    To copy to clipboard, switch view to plain text mode 
    Only the text rectangle test remaining for this part but no one way works actually :/
    Last edited by Alundra; 9th June 2014 at 14:25.

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListView bad behavior on rename

    Create a custom delegate that reports everything it gets to its editorEvent(). See what events are created when you double-click an item. Then you'll know whether you can do it via the delegate's editorEvent() or not.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Rename a Tab of a QTabWidget
    By Qiieha in forum Qt Programming
    Replies: 8
    Last Post: 27th August 2021, 19:26
  2. Qt Creator Is it possible to rename a project?
    By N3wb in forum Qt Tools
    Replies: 1
    Last Post: 3rd December 2010, 02:14
  3. rename file name
    By weixj2003ld in forum Qt Programming
    Replies: 11
    Last Post: 8th April 2010, 11:27
  4. QFile::rename()
    By Bagstone in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2008, 11:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.