Results 1 to 5 of 5

Thread: QListWidget: double click item -> multiple itemDoubleClicked signals

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    42
    Thanked 8 Times in 8 Posts

    Default Re: QListWidget: double click item -> multiple itemDoubleClicked signals

    Here a sample:

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. #include <QDir>
    5.  
    6. MainWindow::MainWindow(QWidget *parent) :
    7. QMainWindow(parent),
    8. ui(new Ui::MainWindow)
    9. {
    10. ui->setupUi(this);
    11.  
    12. QDir shortcutsFolder(QDir::homePath() + QDir::separator() + m_currentDir);
    13. QFileInfoList shortcuts(shortcutsFolder.entryInfoList(QDir::Files, QDir::Name | QDir::IgnoreCase));
    14.  
    15. foreach (QFileInfo fi, shortcuts){
    16. QListWidgetItem *item = new QListWidgetItem(fi.fileName());
    17. connect(ui->listWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(doSomething(QListWidgetItem*)));
    18. ui->listWidget->addItem(item);
    19. }
    20. }
    21.  
    22. MainWindow::~MainWindow()
    23. {
    24. delete ui;
    25. }
    26.  
    27. void MainWindow::doSomething(QListWidgetItem *item)
    28. {
    29. qDebug() << item->text();
    30. }
    To copy to clipboard, switch view to plain text mode 

    Adding Qt::UniqueConnection to connect line fixes the behaviour.
    Giuseppe CalÃ

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 106 Times in 103 Posts

    Default Re: QListWidget: double click item -> multiple itemDoubleClicked signals

    move
    Qt Code:
    1. connect(ui->listWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(doSomething(QListWidgetItem*)));
    To copy to clipboard, switch view to plain text mode 
    from foreach() loop.
    You're not connecting "item" in there so you need to call it only once.

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

    jiveaxe (22nd March 2012)

  4. #3
    Join Date
    Aug 2007
    Posts
    244
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    42
    Thanked 8 Times in 8 Posts

    Default Re: QListWidget: double click item -> multiple itemDoubleClicked signals

    You're absolutely right. Thanks
    Giuseppe CalÃ

Similar Threads

  1. Replies: 2
    Last Post: 24th June 2009, 15:38
  2. Replies: 6
    Last Post: 5th June 2009, 09:38
  3. Replies: 2
    Last Post: 11th January 2009, 23:24
  4. Multiple Lines per item in a QListWidget/QListView
    By youkai in forum Qt Programming
    Replies: 1
    Last Post: 27th August 2008, 21:44
  5. Replies: 5
    Last Post: 12th January 2006, 15:40

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
  •  
Qt is a trademark of The Qt Company.