Updated by Marina Kolpakova over 12 years ago
Let me first suggest to split #2070 into two independent parts
1. resize window not working
2. icons not visible (only Linux)
# 1. =================== resize window not working. working
// Apply resize on parent widget - and it works:
// window_qt.cpp Line: 1855
<pre><code class="cpp">
void CvWindow::setViewportSize(QSize size)
{
QWidget* view = myView->getWidget();
int dx = size.width();
int dy = size.height();
view->parentWidget()->resize(dx-7, dy);
myView->setSize(size);
}
</code></pre>
// that was the bugfix
// And now a little improvement:
// insert following function e.g. behind cv::moveWindow() in window.cpp :
<pre><code class="cpp">
void cv::adjustWindowPos( const string& winname, int xp, int xwp, int yp, int yhp )
{
// Additional function for % setting of windows:
// all values in % relative to screen resulution:
#ifdef _WIN32
int cx,cy;
cx = GetSystemMetrics(SM_CXSCREEN);
cy = GetSystemMetrics(SM_CYSCREEN);
int x = 0.01 * ( xp * cx );
int y = 0.01 * ( yp * cy );
int neww = 0.01 * (xwp * cx );
int newh = 0.01 * (yhp * cy );
cvMoveWindow( winname.c_str(), x, y );
cvResizeWindow( winname.c_str(),neww, newh );
#else
cvAdjustWindowPosQt( winname.c_str(), xp, xwp, yp, yhp );
#endif
}
</code></pre>
Additionally
// additional modify WindowQt.cpp:
// in case of Linux we do not have GetSystemMetrics
// so let it do by Qt, but one more include is nesseary:
<pre><code class="cpp">
#include <QDesktopWidget>
CV_IMPL void cvAdjustWindowPosQt( const char * name, int xp, int xwp, int yp, int yhp )
{
int cx,cy;
QDesktopWidget* pDeskWid = QApplication::desktop() ;
QRect ScreenGeo = pDeskWid->screenGeometry(); // needs #include <QDesktopWidget>
cx = ScreenGeo.width();
cy = ScreenGeo.height();
int x = 0.01 * ( xp * cx );
int y = 0.01 * ( yp * cy );
int neww = 0.01 * (xwp * cx );
int newh = 0.01 * (yhp * cy );
cvMoveWindow( name, x, y );
cvResizeWindow( name, neww, newh );
}
</code></pre>
# 2. =================== icons not visible (only Linux):
It was possible to reproduce this bug for me using Ubuntu
(it works well with Windows XP + Windows 7)
<pre><code class="cpp">
vect_QActions[0] = new QAction(QIcon(":/left-icon"), "Panning left (CTRL+arrowLEFT)", this);
</code></pre>
I just avoided to use QActions and the QIcon inside using QButton and other controls...
To avoid this bug I wrote some code to read the whole configuration of a button bar
from a *.cfg
In this way you have a free order of several contol types
( all QT, so only QT New function in the moment)
I could contibute it, but some changes necessary in the window_QT.cpp code of:
//--------------------Google Code 2010 -- Yannick Verdie--------------------//
Is it welcome ?
1. resize window not working
2. icons not visible (only Linux)
# 1. =================== resize window not working. working
// Apply resize on parent widget - and it works:
// window_qt.cpp Line: 1855
<pre><code class="cpp">
void CvWindow::setViewportSize(QSize size)
{
QWidget* view = myView->getWidget();
int dx = size.width();
int dy = size.height();
view->parentWidget()->resize(dx-7, dy);
myView->setSize(size);
}
</code></pre>
// that was the bugfix
// And now a little improvement:
// insert following function e.g. behind cv::moveWindow() in window.cpp :
<pre><code class="cpp">
void cv::adjustWindowPos( const string& winname, int xp, int xwp, int yp, int yhp )
{
// Additional function for % setting of windows:
// all values in % relative to screen resulution:
#ifdef _WIN32
int cx,cy;
cx = GetSystemMetrics(SM_CXSCREEN);
cy = GetSystemMetrics(SM_CYSCREEN);
int x = 0.01 * ( xp * cx );
int y = 0.01 * ( yp * cy );
int neww = 0.01 * (xwp * cx );
int newh = 0.01 * (yhp * cy );
cvMoveWindow( winname.c_str(), x, y );
cvResizeWindow( winname.c_str(),neww, newh );
#else
cvAdjustWindowPosQt( winname.c_str(), xp, xwp, yp, yhp );
#endif
}
</code></pre>
Additionally
// additional modify WindowQt.cpp:
// in case of Linux we do not have GetSystemMetrics
// so let it do by Qt, but one more include is nesseary:
<pre><code class="cpp">
#include <QDesktopWidget>
CV_IMPL void cvAdjustWindowPosQt( const char * name, int xp, int xwp, int yp, int yhp )
{
int cx,cy;
QDesktopWidget* pDeskWid = QApplication::desktop() ;
QRect ScreenGeo = pDeskWid->screenGeometry(); // needs #include <QDesktopWidget>
cx = ScreenGeo.width();
cy = ScreenGeo.height();
int x = 0.01 * ( xp * cx );
int y = 0.01 * ( yp * cy );
int neww = 0.01 * (xwp * cx );
int newh = 0.01 * (yhp * cy );
cvMoveWindow( name, x, y );
cvResizeWindow( name, neww, newh );
}
</code></pre>
# 2. =================== icons not visible (only Linux):
It was possible to reproduce this bug for me using Ubuntu
(it works well with Windows XP + Windows 7)
<pre><code class="cpp">
vect_QActions[0] = new QAction(QIcon(":/left-icon"), "Panning left (CTRL+arrowLEFT)", this);
</code></pre>
I just avoided to use QActions and the QIcon inside using QButton and other controls...
To avoid this bug I wrote some code to read the whole configuration of a button bar
from a *.cfg
In this way you have a free order of several contol types
( all QT, so only QT New function in the moment)
I could contibute it, but some changes necessary in the window_QT.cpp code of:
//--------------------Google Code 2010 -- Yannick Verdie--------------------//
Is it welcome ?