Results 1 to 2 of 2

Thread: QCombobox Click Signal/Event

  1. #1
    Join Date
    Jun 2016
    Posts
    9
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default QCombobox Click Signal/Event

    Hi every one

    I've a question to qcombobox. In my application I would add all current Serial ports to the Combo box during the runtime. I tried to update the list, when the user clicks on the Combobox (read only).

    After some searching I found something:
    http://www.qtcentre.org/threads/946-...from-QCombobox
    But the problem is, that the Event function is never called... so where is my fault?

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QQueue>
    6. #include <QLineSeries>
    7. #include <QSerialPortInfo>
    8.  
    9. namespace Ui {
    10. class MainWindow;
    11. }
    12.  
    13.  
    14. class MainWindow : public QMainWindow
    15. {
    16.  
    17. public:
    18. explicit MainWindow(QWidget *parent = 0);
    19. ~MainWindow();
    20.  
    21. private:
    22. Ui::MainWindow *ui;
    23.  
    24. public slots:
    25. void vUpdatePortList();
    26.  
    27. protected:
    28. bool bEventFilter(QObject* o, QEvent* e);
    29. };
    30.  
    31. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. #include <QLabel>
    4. #include <QTimer>
    5. #include <QChartView>
    6. #include <QValueAxis>
    7. #include <QLineSeries>
    8. #include <QMessageBox>
    9. #include <QSortFilterProxyModel>
    10.  
    11.  
    12. MainWindow::MainWindow(QWidget *parent) :
    13. QMainWindow(parent),
    14. ui(new Ui::MainWindow),
    15. {
    16. ui->setupUi(this);
    17.  
    18. const QList<QSerialPortInfo> portList(QSerialPortInfo::availablePorts());
    19. int i = 0;
    20. foreach (QSerialPortInfo port, portList)
    21. {
    22. ui->comboBoxPorts->addItem(port.portName());
    23. ui->comboBoxPorts->setItemData(i, port.description(), Qt::ToolTipRole);
    24. i++;
    25. }
    26. // Sort List
    27. QSortFilterProxyModel* proxy = new QSortFilterProxyModel(ui->comboBoxPorts);
    28. proxy->setSourceModel(ui->comboBoxPorts->model());
    29. ui->comboBoxPorts->model()->setParent(proxy);
    30. ui->comboBoxPorts->model()->sort(0);
    31.  
    32.  
    33. ui->comboBoxPorts->installEventFilter(this);
    34. }
    35.  
    36. MainWindow::~MainWindow()
    37. {
    38. delete ui;
    39. }
    40.  
    41. bool MainWindow::bEventFilter(QObject* o, QEvent* e)
    42. {
    43. if(e->type() == QEvent::Show)
    44. {
    45. vUpdatePortList();
    46. ui->textEdit->append("TRUE");
    47. return true;
    48. }
    49. else
    50. {
    51. ui->textEdit->append("FALSE");
    52. return false;
    53. }
    54. }
    55.  
    56. void MainWindow::vUpdatePortList()
    57. {
    58. ui->textEdit->append("Hallo");
    59. }
    To copy to clipboard, switch view to plain text mode 

    Isn't there any Click-Signal in QT?

    Thank you for helping me.
    Best regards, P51D

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QCombobox Click Signal/Event

    Isn't there any Click-Signal in QT?
    Not for QComboBox. The event filter is the best way to go. As the other post said, you probably -don't- want to look for the Show event, because that only occurs once, when the combo box is first made visible. The way you look for a "click" is to watch for a pair of MouseButtonPress and MouseButtonRelease events that occur within a short time period, or by looking for the FocusIn event inside of your event filter.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. How to add items while click on QCombobox
    By RameshNani in forum Qt Programming
    Replies: 2
    Last Post: 4th February 2014, 07:07
  2. Replies: 4
    Last Post: 11th January 2014, 03:06
  3. QComboBox Item Right Click
    By wirasto in forum Qt Programming
    Replies: 9
    Last Post: 13th January 2013, 18:44
  4. pushButton click event
    By aj2903 in forum Qt Programming
    Replies: 1
    Last Post: 9th June 2009, 11:19
  5. mouse click event
    By vijay anandh in forum Qt Programming
    Replies: 1
    Last Post: 1st May 2006, 09:24

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.