Skip to content

Commit d84c7e5

Browse files
GregoryMorsealalek
authored andcommitted
Merge pull request opencv#10649 from GregoryMorse:patch-3
* Fix for QT image window rectangle * Update window_QT.h * Update window_QT.cpp * trailing whitespace * highgui: fix QT getWindowImageRect()
1 parent c89ae6e commit d84c7e5

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

modules/highgui/src/window_QT.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -967,13 +967,7 @@ CvRect GuiReceiver::getWindowRect(QString name)
967967
if (!w)
968968
return cvRect(-1, -1, -1, -1);
969969

970-
QPoint org = w->myView->mapToGlobal(new QPoint(0, 0));
971-
#ifdef HAVE_QT_OPENGL
972-
if (isOpenGl()) {
973-
return cvRect(w->myView->pos().x() + org.x, w->myView->pos().y() + org.y, w->myView->width(), w->myView->height());
974-
} else
975-
#endif
976-
return cvRect(w->myView->viewport()->pos().x() + org.x, w->myView->viewport()->pos().y() + org.y, w->myView->viewport()->width(), w->myView->viewport()->height());
970+
return w->getWindowRect();
977971
}
978972

979973
double GuiReceiver::isFullScreen(QString name)
@@ -1781,6 +1775,13 @@ void CvWindow::setRatio(int flags)
17811775
myView->setRatio(flags);
17821776
}
17831777

1778+
CvRect CvWindow::getWindowRect()
1779+
{
1780+
QWidget* view = myView->getWidget();
1781+
QRect local_rc = view->geometry(); // http://doc.qt.io/qt-5/application-windows.html#window-geometry
1782+
QPoint global_pos = /*view->*/mapToGlobal(QPoint(local_rc.x(), local_rc.y()));
1783+
return cvRect(global_pos.x(), global_pos.y(), local_rc.width(), local_rc.height());
1784+
}
17841785

17851786
int CvWindow::getPropWindow()
17861787
{

modules/highgui/src/window_QT.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ class CvWindow : public CvWinModel
299299
double getRatio();
300300
void setRatio(int flags);
301301

302+
CvRect getWindowRect();
302303
int getPropWindow();
303304
void setPropWindow(int flags);
304305

modules/highgui/test/test_gui.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ void CV_HighGuiOnlyGuiTest::run( int /*start_from */)
8484
waitKey(500);
8585

8686
ts->printf(ts->LOG, "GUI 8\n");
87-
getWindowImageRect("Win");
87+
Rect rc = getWindowImageRect("Win");
88+
std::cout << "window image rect: " << rc << std::endl;
8889

8990
ts->printf(ts->LOG, "GUI 9\n");
9091
destroyAllWindows();

0 commit comments

Comments
 (0)