我用Qt 画了一个地图,想要在状态栏显示鼠标坐标,我遇到的问题是,坐标不能随mouseMoveEvent函数实时刷新

我用Qt 画了一个地图,想要在状态栏显示鼠标坐标,我遇到的问题是,坐标不能随mouseMoveEvent函数实时刷新,第1张

全部重新改了,代码如下

// mainwindowh 头文件

#ifndef MAINWINDOW_H

#define MAINWINDOW_H

#include <QtGui/QMainWindow>

#include <QStatusBar>

#include <QMouseEvent>

class MainWindow : public QMainWindow

{

Q_OBJECT

public:

MainWindow(QWidget parent = 0);

~MainWindow();

protected:

void mouseMoveEvent(QMouseEvent );

private:

QStatusBar m_pStatus;

};

#endif // MAINWINDOW_H

//mainwindowcpp

#include "mainwindowh"

MainWindow::MainWindow(QWidget parent)

: QMainWindow(parent)

{

setMouseTracking(true);

m_pStatus = new QStatusBar();

setStatusBar(m_pStatus);

m_pStatus->showMessage("application init ok!");

}

void MainWindow::mouseMoveEvent(QMouseEvent event)

{

QPoint pos = event->pos();

m_pStatus->showMessage(QString("x:%1,y:%2")arg(posx())arg(posy()));

}

MainWindow::~MainWindow()

{

}

经过测试,完全ok,唉

qDebug() << this->parentWidget()->x();

你调用parent()得到的是QObject对象,当然没法拿到坐标

方法一:用QPolygon来保存六边形的点,所有的polygon放在QVector中,鼠标点击的时候查找点属于哪个polygon

方法二:QGraphicsView/scene /item实现

The method selectionModel() return a QItemSelectionModel

You can use QItemSelectionModel class to check/change/other selection(s)

Example:

QItemSelectionModel select = yourTableview->selectionModel();

select->hasSelection() //check if has selection

select->selectedRows() // return selected row(s)

select->selectedColumns() // return selected column(s)

Example:

QModelIndexList indexList = yourTableView->selectionModel()->selectedIndexes();

int row;

foreach (QModelIndex index, indexList) {

row = indexrow();

}

以上就是关于我用Qt 画了一个地图,想要在状态栏显示鼠标坐标,我遇到的问题是,坐标不能随mouseMoveEvent函数实时刷新全部的内容,包括:我用Qt 画了一个地图,想要在状态栏显示鼠标坐标,我遇到的问题是,坐标不能随mouseMoveEvent函数实时刷新、qt中,子窗口如何得到父窗口的当前坐标qwidget parent、Qt画图以及坐标问题等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/9716909.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-01
下一篇 2023-05-01

发表评论

登录后才能评论

评论列表(0条)

保存