-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
基于示例代码添加QGraphicsView,里面显示的QGraphicsItem下半部分区域无法接收鼠标事件 #93
Comments
是不是在标题栏区域里了? |
标题栏区域中的控件(一部分在也算),要用setHitTestVisible手动开启交互事件,否则无法响应任何交互,请仔细看自述文件 |
设置了setHitTestVisible之后一样不行 MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
installWindowAgent();
//#if 1
// auto clockWidget = new ClockWidget();
// clockWidget->setObjectName(QStringLiteral("clock-widget"));
// clockWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// setCentralWidget(clockWidget);
//#else
// auto webView = new QWebEngineView();
// webView->load(QUrl("https://www.baidu.com"));
// setCentralWidget(webView);
//#endif
centralWidget = new QWidget(this);
auto layout = new QVBoxLayout(centralWidget);
view = new QGraphicsView(this);
scene = new QGraphicsScene(this);
rectItem = new QGraphicsRectItem(0, 0, 100, 100);
rectItem->setBrush(Qt::red);
rectItem->setFlag(QGraphicsItem::ItemIsMovable);
scene->addItem(rectItem);
auto ellipseItem = new QGraphicsEllipseItem(150, 0, 100, 100);
ellipseItem->setBrush(Qt::green);
ellipseItem->setFlag(QGraphicsItem::ItemIsMovable);
scene->addItem(ellipseItem);
auto textItem = new QGraphicsTextItem("Drag me!");
textItem->setPos(300, 0);
textItem->setFlag(QGraphicsItem::ItemIsMovable);
scene->addItem(textItem);
view->setScene(scene);
view->setMouseTracking(true);
layout->addWidget(view);
windowAgent->setHitTestVisible(centralWidget,true);
// windowAgent->setHitTestVisible(view,true);
setCentralWidget(centralWidget);
loadStyleSheet(Dark);
setWindowTitle(tr("Example MainWindow"));
resize(800, 600);
// windowAgent->centralize();
} |
先更新到 Qt 6.6.2 及以上再说 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
qt版本:6.5.3 msvc 2019
系统:windows11
在主窗口中添加了一个 QGraphicsView,创建多个不同类型的 QGraphicsItem (QGraphicsRectItem、QGraphicsEllipseItem 和 QGraphicsTextItem)。当鼠标位于这些 QGraphicsItem 的下半部分区域时候,QGraphicsItem无法接收到鼠标点击事件,具体表现为无法点击下半部分进行拖动。
The text was updated successfully, but these errors were encountered: