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?
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QQueue>
#include <QLineSeries>
#include <QSerialPortInfo>
namespace Ui {
class MainWindow;
}
{
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private:
Ui::MainWindow *ui;
public slots:
void vUpdatePortList();
protected:
};
#endif // MAINWINDOW_H
Code:
#include "mainwindow.h"
#include <QLabel>
#include <QTimer>
#include <QChartView>
#include <QValueAxis>
#include <QLineSeries>
#include <QMessageBox>
#include <QSortFilterProxyModel>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow),
{
ui->setupUi(this);
const QList<QSerialPortInfo> portList(QSerialPortInfo::availablePorts());
int i = 0;
foreach (QSerialPortInfo port, portList)
{
ui->comboBoxPorts->addItem(port.portName());
ui->comboBoxPorts->setItemData(i, port.description(), Qt::ToolTipRole);
i++;
}
// Sort List
proxy->setSourceModel(ui->comboBoxPorts->model());
ui->comboBoxPorts->model()->setParent(proxy);
ui->comboBoxPorts->model()->sort(0);
ui->comboBoxPorts->installEventFilter(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
{
{
vUpdatePortList();
ui->textEdit->append("TRUE");
return true;
}
else
{
ui->textEdit->append("FALSE");
return false;
}
}
void MainWindow::vUpdatePortList()
{
ui->textEdit->append("Hallo");
}
Isn't there any Click-Signal in QT?
Thank you for helping me.
Best regards, P51D
Re: QCombobox Click Signal/Event
Quote:
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.