Each QTabWidget TAB is different. One of the tab is actually a QTableView. In this QTableView I have built a delegate for rows to display text as a hyper links which totally does not work for on mac . Below code works for linux and win, so text is underlined on mouse over a row on a text. I need to put the cursor: pointer as well to really look like a hyperlinks.
This does not work even for linux and win.
if (optionV4.
state & QStyle::State_MouseOver) { doc.setDefaultStyleSheet("a:hover {text-decoration: underline; cursor:pointer;}");
} else {
doc.setDefaultStyleSheet("a {text-decoration: none;cursor:pointer;}");
}
if (optionV4.state & QStyle::State_MouseOver) {
doc.setDefaultStyleSheet("a:hover {text-decoration: underline; cursor:pointer;}");
} else {
doc.setDefaultStyleSheet("a {text-decoration: none;cursor:pointer;}");
}
To copy to clipboard, switch view to plain text mode
So instead thought I will get at least working changing cursor by using mouseMoveEvent for all platforms
{
this
->setCursor
( QCursor( Qt
::ArrowCursor ));
QStandardItem *item
= model
()->itemFromIndex
(_proxyModel
->mapToSource
(index
));
if (item)
{
if (item->column() == 4 || item->column() == 3 || item->column() == 1 )
{
this
->setCursor
( QCursor( Qt
::PointingHandCursor ));
}
}
}
void Table::mouseMoveEvent(QMouseEvent *event)
{
this->setCursor( QCursor( Qt::ArrowCursor ));
QModelIndex index = indexAt( event->pos());
QStandardItem *item = model()->itemFromIndex(_proxyModel->mapToSource(index));
if (item)
{
if (item->column() == 4 || item->column() == 3 || item->column() == 1 )
{
this->setCursor( QCursor( Qt::PointingHandCursor ));
}
}
}
To copy to clipboard, switch view to plain text mode
But a code above works just for a linux and win. No MAC.
For mac behave is different. When I mouseOver on row nothing happening. But when I press and don't let the mouse button, moving around rows it's doing the job, cursor is changing just fine. But I don't really want to keep the button. It must behave like hyperlinks so thought setMouseTracking will fix it.
Was wrong it must be something else.
The real code of QTabWidget for my table keeps the QWidget with controls and table
so
layout->addWidget(controls);
layout
->addWidget
(MyTable
()); <
- here is my
QTableView
activitiesPage->setLayout(layout);
int index = tabWidget()->addTab(tablePage, "tablePage");
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(controls);
layout->addWidget(MyTable()); <- here is my QTableView
QWidget *activitiesPage = new QWidget(this);
activitiesPage->setLayout(layout);
int index = tabWidget()->addTab(tablePage, "tablePage");
To copy to clipboard, switch view to plain text mode
controls, it is a QToolBar which gives me a buttons to sort the QTableView model.
- And funny is that when I will press the one of the sort buttons and the model will change, hyperlinks start to work. But the model must actually change.
- removing controls and tablePage and putting QTableView straight to TAB does not fix it.
- another funny thing that I automatically add few tabs. QtableView as first ONE. if I comment the below line mouse event works fine as well.
tabWidget()->setCurrentWidget(otherpagethenQTableView);
tabWidget()->setCurrentWidget(otherpagethenQTableView);
To copy to clipboard, switch view to plain text mode
This gave me to think that this is some focusing problem but any of the commented lines below don't help either.
void MainWindow::currentTabChanged(int index)
{
QWidget *widget
= _tabWidget
->widget
(index
);
if (widget)
{
tabWidget()->setCurrentWidget(widget);
// if (index == 0)
// {
// Mytable()->setFocus();
// Mytable()->activateWindow();
// Mytable()->viewport()->setFocus();
// Mytable()->viewport()->focusWidget();
// Mytable()->viewport()->activateWindow();
// Mytable()->viewport()->setMouseTracking(true);
// Mytable()->viewport()->setEnabled(true);
// Mytable()->viewport()->update();
// }
}
}
void MainWindow::currentTabChanged(int index)
{
QWidget *widget = _tabWidget->widget(index);
if (widget)
{
tabWidget()->setCurrentWidget(widget);
// if (index == 0)
// {
// Mytable()->setFocus();
// Mytable()->activateWindow();
// Mytable()->viewport()->setFocus();
// Mytable()->viewport()->focusWidget();
// Mytable()->viewport()->activateWindow();
// Mytable()->viewport()->setMouseTracking(true);
// Mytable()->viewport()->setEnabled(true);
// Mytable()->viewport()->update();
// }
}
}
To copy to clipboard, switch view to plain text mode
AND ITS ALL ABOUT MAC
Thanks for looking.
Added after 7 minutes:
One more
I use QSortFilterProxyModel to sort a model and removing it does not help.
Removing delegates does not help either.
Bookmarks