[SOLVED] QWidget - make a part transparent for mouse event,
-
Hey SGaist,
EventFilter are really interesting and powerful, I will use them more often.
I have set up my RepeatWidget events to be filtered by my tableView eventFilter. But it seems my widget only trigger "Enter" and "Leave" events. I don't have the mouseMoveEvent by default?
Thanks!
Here is the code :
Set up object to use eventFilter:
@ RepeatWidget *repeatWidgetCopy = new RepeatWidget(repData, ui->tableView->viewport());
repeatWidgetCopy->setMouseTracking(true);
repeatWidgetCopy->installEventFilter(ui->tableView);ui->tableView->horizontalHeader()->setMouseTracking(true); ui->tableView->verticalHeader()->setMouseTracking(true); connect(ui->tableView, SIGNAL(entered(QModelIndex)), ui->tableView, SLOT(setCursor(QModelIndex)) ); ui->tableView->horizontalHeader()->installEventFilter(ui->tableView); ui->tableView->verticalHeader()->installEventFilter(ui->tableView);@
eventFilter:
@bool TableViewInterval::eventFilter(QObject *watched, QEvent *event) {qDebug() << "watched object" << watched << "event:" << event << "eventType" << event->type(); /// Change cursor to normal when hovering on Headers; if(qobject_cast<QHeaderView*>(watched) != nullptr && event->type() == QEvent::HoverMove) { qDebug() << "HoverMove" << watched; QApplication::setOverrideCursor(Qt::ArrowCursor); } else if (watched->objectName() == "RepeatWidget") { qDebug() << " got here now Repeat_Widget" << event->type() << event; if (event->type() == QEvent::MouseMove) { qDebug() << "RepeatWidget Mouse move now!"; /// Check position to see if we are at column 0, if so, change cursor QMouseEvent *mouseMoveEvent = static_cast<QMouseEvent*>(event); QPoint pos = mouseMoveEvent->pos(); qDebug() << "pos" << pos; // QModelIndex index = ui->tableView->indexAt(pos); // int row = index.row(); // if (index.isValid()) // { // qDebug() << "index is" << row; } } return false;
}
@ -
Problem seems to be with the custom QWidget that trigger MouseMove only once when it enter the Widget, but doesn't trigger more when I move inside the Widget itself
log :
watched object RepeatWidget(0x3d3c510, name = "RepeatWidget") event: QMouseEvent(MouseMove, 0, 0, 0) eventType 5
RepeatWidget Mouse move now!
pos QPoint(516,73) -
mouseMove event is only called if you are keeping a mouse button pressed. The other way to get the mouse move event continuously is to use setMouseGrabEnabled but have a look at the documentation before using it
-
Yo SGaist,
Been lazy, I redesigned a new QWidget containing 2 QWidgets, one of the left with transparent mouse event and the one of the left with the controls can still get the mouse events:Here it is if it can help anyone:
https://www.dropbox.com/s/66mp8rj9g4ybtw0/interfaceRepeat22.pngOnly thing to fix is a small gap in the border of the two QWidget frame, even with 0 margin they are not close enough, will investigate..
thanks for the help! -
Did you also set the spacing to 0 ?
-
Yeah all the Layout have 0 margins and spacing, there must be another element that factor in.. it's like a 1mm margin, the QWidget are not touching but almost.. weird
I tried negative margin on the layouts but not working so far,
Thanks -
The space doesn't mean the widget's not right. Are you giving him a fixed size ?
-
The SizePolicy is set to minimumExpending (horizontal and vertical), not fixed.
The size is set dynamicly at run time when user press a button this is called :
Here it is :@ RepeatData *repData = new RepeatData(id, firstRow, lastRow, numberRepeat);
RepeatWidget *repeatWidgetCopy = new RepeatWidget(repData, ui->tableView->viewport());
repeatWidgetCopy->move(rectCompleteSelection.topLeft());
repeatWidgetCopy->resize(rectCompleteSelection.size().width() + 190, rectCompleteSelection.size().height());
repeatWidgetCopy->show();@Also some attribute that may interest you :
@ ui->widget_left->setAttribute(Qt::WA_TransparentForMouseEvents);
setAttribute(Qt::WA_TranslucentBackground);
setWindowFlags(Qt::FramelessWindowHint );@Except that, it's a standard QWidget containing 2 QWidget that have a stylsheet with a border-color. Thanks!
-
Can you show the left widget not transparent just to see how far it goes ?
-
Hmm not sure what you mean, the widget is transparent only for mouse event, both widget just have a border, no background
https://www.dropbox.com/s/66mp8rj9g4ybtw0/interfaceRepeat22.pngThanks
-
Sorry, I meant translucent
-
yeah this flag doesn't do much actually, same thing commented or not :/
-
It's not a major bug, I may change the design to show a verital doted line between both widget, I'll see if I can't fix it i'll change it, thanks
-
To have two QFrame without space between them:
this code worked (added 0px border because default is 1px I think, that was the problem!)@#frame_border_left {
border-left : 4px solid qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(7,0,62,255), stop:1 rgba(13, 0, 158, 255));
border-top: 4px solid qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(7,0,62,255), stop:1 rgba(13, 0, 158, 255));
border-bottom: 4px solid qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(7,0,62,255), stop:1 rgba(13, 0, 158, 255));
border-right : 0px;}
#frame_border_right {
border-left : 0px;
border-right : 4px solid qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(7,0,62,255), stop:1 rgba(13, 0, 158, 255));
border-top: 4px solid qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(7,0,62,255), stop:1 rgba(13, 0, 158, 255));
border-bottom: 4px solid qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(7,0,62,255), stop:1 rgba(13, 0, 158, 255));}@