#ifndef QPlaceHolder_H
#define QPlaceHolder_H
#include <QWinWidget>
#include <QHBoxLayout>
#include <QMessageBox>
template <typename QWidgetType>
class QPlaceHolder : public QWinWidget {
public:
QPlaceHolder(CWnd* parentWnd) : QWinWidget(parentWnd)
{
myWidget = new QWidgetType(this);
hbox->setContentsMargins(0, 0, 0, 0);
hbox->addWidget(myWidget);
myWidget->show();
QWinWidget::show();
}
void move(int x, int y)
{
HWND parentwnd = GetParent(wnd);
QMessageBox::information(NULL,
"Before moving QPlaceHolder",
QString("curx=%1, cury=%2, curwidth=%3, curheight=%4").
arg(this
->pos
().
x()).
arg(this
->pos
().
y()).
arg(this
->width
()).
arg(this
->height
()));
RECT parentRect;
RECT myRect;
GetWindowRect(parentwnd, &parentRect);
GetWindowRect(wnd, &myRect);
POINT topleft;
topleft.x = parentRect.left + x;
topleft.y = parentRect.top + y;
ScreenToClient(parentwnd, &topleft);
int width = myRect.right - myRect.left;
int height = myRect.bottom - myRect.top;
MoveWindow(wnd, topleft.x, topleft.y, width, height, TRUE);
UpdateWindow(wnd);
}
QWidgetType* widget()
{
return myWidget;
}
private:
QWidgetType* myWidget;
};
#endif //QPlaceHolder_H
#ifndef QPlaceHolder_H
#define QPlaceHolder_H
#include <QWinWidget>
#include <QHBoxLayout>
#include <QMessageBox>
template <typename QWidgetType>
class QPlaceHolder : public QWinWidget {
public:
QPlaceHolder(CWnd* parentWnd) : QWinWidget(parentWnd)
{
myWidget = new QWidgetType(this);
QHBoxLayout* hbox = new QHBoxLayout(this);
hbox->setContentsMargins(0, 0, 0, 0);
hbox->addWidget(myWidget);
myWidget->show();
QWinWidget::show();
}
void move(int x, int y)
{
HWND wnd = QWidget::winId();
HWND parentwnd = GetParent(wnd);
QMessageBox::information(NULL, "Before moving QPlaceHolder", QString("curx=%1, cury=%2, curwidth=%3, curheight=%4").arg(this->pos().x()).arg(this->pos().y()).arg(this->width()).arg(this->height()));
RECT parentRect;
RECT myRect;
GetWindowRect(parentwnd, &parentRect);
GetWindowRect(wnd, &myRect);
POINT topleft;
topleft.x = parentRect.left + x;
topleft.y = parentRect.top + y;
ScreenToClient(parentwnd, &topleft);
int width = myRect.right - myRect.left;
int height = myRect.bottom - myRect.top;
MoveWindow(wnd, topleft.x, topleft.y, width, height, TRUE);
UpdateWindow(wnd);
}
QWidgetType* widget()
{
return myWidget;
}
private:
QWidgetType* myWidget;
};
#endif //QPlaceHolder_H
To copy to clipboard, switch view to plain text mode
Bookmarks