QsqlTableModel/QtableView Event Filter Capture
-
I am trying to develop an email reader for my visually impaired father who is 94. I am using QsqlTableModel and QtableView to create a list of email files from the dbx file. The table displays 3 columns for Subject, From, and Date. This works fine but since the minimum font size he can read is 34, the text is truncated in each column. I would like to improve the design by allowing him to see all the text under the selected row of the table in a temporary text box similar to a qtooltip. The two
approaches I have tried are Mouse Over(Hover ) and MouseButtonPress. In the Mouse Over approach I would like the text to display when the mouse cursor is over the selected row/column(i.e. cell) and disappear when the mouse cursor is not over the selected row/column (i.e. cell). The following code snippet is what I have tried:@
TableEditor::TableEditor(const QString &tableName, QWidget *parent)
: QDialog(parent)
{
setAttribute(Qt::WA_Hover,true);
//Also tried these
//setMouseTracking(true);
//view->viewport()->setMouseTracking(true);
//view->setMouseTracking(true);
//view->viewport()->setAttribute(Qt::WA_Hover,true);
//view->setAttribute(Qt::WA_Hover,true);// This code allows total row to be highlighted and disable editing
view->setSelectionBehavior(QAbstractItemView::SelectRows);
view->setSelectionMode(QAbstractItemView::SingleSelection);
view->setEditTriggers(QAbstractItemView::NoEditTriggers); //Could this cause the problem
.
.
.
void TableEditor::mouseHoverEvent(QHoverEvent *event)
{
if ((event->type() == QHoverEvent::HoverEnter)) {
accept();
//Put code here to open and display dialog (I open message box for testing for testing purposes)
update();
}
else if ((event->type() == QHoverEvent::HoverLeave)) {
accept();
//put code here to close dialog (I open message box for testing for testing purposes)
update();
}
}
@I don't seem to be capturing the event which I think the setAttribute(Qt::WA_Hover,true) is supposed to do? I also do not understand the logic necessary to trigger the event when the mouse cursor is over the selected row? Could it be the code that disables edit triggers that is causing the problem?
The second approach I tried is to detect a right mouse button press event using an event filter. I would like the text to display when the right mouse button is pressed and held over a selected cell. The text would diappear when the right mouse button is released. The code snippet code snippet I have so far for this is:
@
TableEditor::TableEditor(const QString &tableName, QWidget *parent)
: QDialog(parent)
{
.
.
.
view -> installEventFilter(this);
.
.
bool TableEditor::eventFilter(QObject *obj, QEvent *event)
{
if (obj == view) {
if (event->type() == QEvent::MouseButtonPress) { //This if does not capture MouseButtonPress event type does work for KeyPress
QMouseEvent mouseEvent = static_cast<QMouseEvent>(event);
if ( mouseEvent->button() == Qt::RightButton ) {
//Put code here to open text (I open message box for testing purposes)
return true;
}
} else {
return false;
}
if (event->type() == QEvent::MouseButtonRelease) {
QMouseEvent mouseEvent = static_cast<QMouseEvent>(event);
if ( mouseEvent->button() == Qt::RightButton ) {
//Put code here to open text (I open message box for testing purposes)
return true;
}
} else {
return false;
}
} else {
// pass the event on to the parent class
// return TableEditor::eventFilter(obj, event);
return false;
}
}
@Again I do not seem to be capturing the event. The if (event->type() == QEvent::MouseButtonPress) does not capture MouseButtonPress event type. It does work for KeyPress. I also need to add logic to make sure I am over selected row.
Any help anyone can give me would be appreciated. Thanks.
[edit: Mark up code, Tobias]