Qt error Invalid use of incomplete type 'class UI::FrameLess'












0















I keep getting this error and I don't know why. It just says incomplete type of my class FrameLess. I don't think im missing including any files. I also want to specify that I have a mainwindow besides this widget and im trying to implement a UI form for my class FrameLess. Any help would be great. Thanks!



frameless.h



#ifndef FRAMELESS_H
#define FRAMELESS_H

#pragma once
#include <QtWidgets/QWidget>
#include <QtWidgets/QRubberBand>
#include <QtCore/QObject>
#include <QtCore/QEvent>
#include <QtCore/QRect>
#include <QtCore/QPoint>
#include <QtCore/Qt>
#include <QtGui/QHoverEvent>
#include <QtGui/QMouseEvent>
#include <QMainWindow>

namespace Ui {
class FrameLess;
}


class FrameLess : public QObject {
Q_OBJECT

public:
enum Edge {
None = 0x0,
Left = 0x1,
Top = 0x2,
Right = 0x4,
Bottom = 0x8,
TopLeft = 0x10,
TopRight = 0x20,
BottomLeft = 0x40,
BottomRight = 0x80,
};
Q_ENUM(Edge);
Q_DECLARE_FLAGS(Edges, Edge);

FrameLess(QWidget *target);

void setBorderWidth(int w) {
_borderWidth = w;
}
int borderWidth() const {
return _borderWidth;
}

protected:
bool eventFilter(QObject *o, QEvent *e) override;
void mouseHover(QHoverEvent*);
void mouseLeave(QEvent*);
void mousePress(QMouseEvent*);
void mouseRealese(QMouseEvent*);
void mouseMove(QMouseEvent*);
void updateCursorShape(const QPoint &);
void calculateCursorPosition(const QPoint &, const QRect &, Edges &);

private:
QWidget *_target = nullptr;
QRubberBand *_rubberband = nullptr;
bool _cursorchanged;
bool _leftButtonPressed;
Edges _mousePress = Edge::None;
Edges _mouseMove = Edge::None;
int _borderWidth;
Ui::FrameLess *ui;
QPoint _dragPos;
bool _dragStart = false;



};

Q_DECLARE_OPERATORS_FOR_FLAGS(FrameLess::Edges);
#endif


frameless.cpp:



#include "frameless.h"
#include "ui_frameless.h"

FrameLess::FrameLess(QWidget *target) :_target(target),_cursorchanged(false),_leftButtonPressed(false),_borderWidth(5),_dragPos(QPoint()), ui(new Ui::FrameLess)
{
// ui->setup(this);
_target->setMouseTracking(true);
_target->setWindowFlags(Qt::FramelessWindowHint);
_target->setAttribute(Qt::WA_Hover);
_target->installEventFilter(this);
_rubberband = new QRubberBand(QRubberBand::Rectangle);
}

bool FrameLess::eventFilter(QObject *o, QEvent*e) {
if (e->type() == QEvent::MouseMove ||
e->type() == QEvent::HoverMove ||
e->type() == QEvent::Leave ||
e->type() == QEvent::MouseButtonPress ||
e->type() == QEvent::MouseButtonRelease) {

switch (e->type()) {
case QEvent::MouseMove:
mouseMove(static_cast<QMouseEvent*>(e));
return true;
break;
case QEvent::HoverMove:
mouseHover(static_cast<QHoverEvent*>(e));
return true;
break;
case QEvent::Leave:
mouseLeave(e);
return true;
break;
case QEvent::MouseButtonPress:
mousePress(static_cast<QMouseEvent*>(e));
return true;
break;
case QEvent::MouseButtonRelease:
mouseRealese(static_cast<QMouseEvent*>(e));
return true;
break;
}
}
else {
return _target->eventFilter(o, e);
}
}

void FrameLess::mouseHover(QHoverEvent *e) {
updateCursorShape(_target->mapToGlobal(e->pos()));
}

void FrameLess::mouseLeave(QEvent *e) {
if (!_leftButtonPressed) {
_target->unsetCursor();
}
}

void FrameLess::mousePress(QMouseEvent *e) {
if (e->button() & Qt::LeftButton) {
_leftButtonPressed = true;
calculateCursorPosition(e->globalPos(), _target->frameGeometry(), _mousePress);
if (!_mousePress.testFlag(Edge::None)) {
_rubberband->setGeometry(_target->frameGeometry());
}
if (_target->rect().marginsRemoved(QMargins(borderWidth(), borderWidth(), borderWidth(), borderWidth())).contains(e->pos())) {
_dragStart = true;
_dragPos = e->pos();
}
}
}

void FrameLess::mouseRealese(QMouseEvent *e) {
if (e->button() & Qt::LeftButton) {
_leftButtonPressed = false;
_dragStart = false;
}
}

void FrameLess::mouseMove(QMouseEvent *e) {
if (_leftButtonPressed) {
if (_dragStart) {
_target->move(_target->frameGeometry().topLeft() + (e->pos() - _dragPos));
}

if (!_mousePress.testFlag(Edge::None)) {
int left = _rubberband->frameGeometry().left();
int top = _rubberband->frameGeometry().top();
int right = _rubberband->frameGeometry().right();
int bottom = _rubberband->frameGeometry().bottom();
switch (_mousePress) {
case Edge::Top:
top = e->globalPos().y();
break;
case Edge::Bottom:
bottom = e->globalPos().y();
break;
case Edge::Left:
left = e->globalPos().x();
break;
case Edge::Right:
right = e->globalPos().x();
break;
case Edge::TopLeft:
top = e->globalPos().y();
left = e->globalPos().x();
break;
case Edge::TopRight:
right = e->globalPos().x();
top = e->globalPos().y();
break;
case Edge::BottomLeft:
bottom = e->globalPos().y();
left = e->globalPos().x();
break;
case Edge::BottomRight:
bottom = e->globalPos().y();
right = e->globalPos().x();
break;
}
QRect newRect(QPoint(left, top), QPoint(right, bottom));
if (newRect.width() < _target->minimumWidth()) {
left = _target->frameGeometry().x();
}
else if (newRect.height() < _target->minimumHeight()) {
top = _target->frameGeometry().y();
}
_target->setGeometry(QRect(QPoint(left, top), QPoint(right, bottom)));
_rubberband->setGeometry(QRect(QPoint(left, top), QPoint(right, bottom)));
}
}
else {
updateCursorShape(e->globalPos());
}
}

void FrameLess::updateCursorShape(const QPoint &pos) {
if (_target->isFullScreen() || _target->isMaximized()) {
if (_cursorchanged) {
_target->unsetCursor();
}
return;
}
if (!_leftButtonPressed) {
calculateCursorPosition(pos, _target->frameGeometry(), _mouseMove);
_cursorchanged = true;
if (_mouseMove.testFlag(Edge::Top) || _mouseMove.testFlag(Edge::Bottom)) {
_target->setCursor(Qt::SizeVerCursor);
}
else if (_mouseMove.testFlag(Edge::Left) || _mouseMove.testFlag(Edge::Right)) {
_target->setCursor(Qt::SizeHorCursor);
}
else if (_mouseMove.testFlag(Edge::TopLeft) || _mouseMove.testFlag(Edge::BottomRight)) {
_target->setCursor(Qt::SizeFDiagCursor);
}
else if (_mouseMove.testFlag(Edge::TopRight) || _mouseMove.testFlag(Edge::BottomLeft)) {
_target->setCursor(Qt::SizeBDiagCursor);
}
else if (_cursorchanged) {
_target->unsetCursor();
_cursorchanged = false;
}
}
}

void FrameLess::calculateCursorPosition(const QPoint &pos, const QRect &framerect, Edges &_edge) {
bool onLeft = pos.x() >= framerect.x() - _borderWidth && pos.x() <= framerect.x() + _borderWidth &&
pos.y() <= framerect.y() + framerect.height() - _borderWidth && pos.y() >= framerect.y() + _borderWidth;

bool onRight = pos.x() >= framerect.x() + framerect.width() - _borderWidth && pos.x() <= framerect.x() + framerect.width() &&
pos.y() >= framerect.y() + _borderWidth && pos.y() <= framerect.y() + framerect.height() - _borderWidth;

bool onBottom = pos.x() >= framerect.x() + _borderWidth && pos.x() <= framerect.x() + framerect.width() - _borderWidth &&
pos.y() >= framerect.y() + framerect.height() - _borderWidth && pos.y() <= framerect.y() + framerect.height();

bool onTop = pos.x() >= framerect.x() + _borderWidth && pos.x() <= framerect.x() + framerect.width() - _borderWidth &&
pos.y() >= framerect.y() && pos.y() <= framerect.y() + _borderWidth;

bool onBottomLeft = pos.x() <= framerect.x() + _borderWidth && pos.x() >= framerect.x() &&
pos.y() <= framerect.y() + framerect.height() && pos.y() >= framerect.y() + framerect.height() - _borderWidth;

bool onBottomRight = pos.x() >= framerect.x() + framerect.width() - _borderWidth && pos.x() <= framerect.x() + framerect.width() &&
pos.y() >= framerect.y() + framerect.height() - _borderWidth && pos.y() <= framerect.y() + framerect.height();

bool onTopRight = pos.x() >= framerect.x() + framerect.width() - _borderWidth && pos.x() <= framerect.x() + framerect.width() &&
pos.y() >= framerect.y() && pos.y() <= framerect.y() + _borderWidth;

bool onTopLeft = pos.x() >= framerect.x() && pos.x() <= framerect.x() + _borderWidth &&
pos.y() >= framerect.y() && pos.y() <= framerect.y() + _borderWidth;

if (onLeft) {
_edge = Left;
}
else if (onRight) {
_edge = Right;
}
else if (onBottom) {
_edge = Bottom;
}
else if (onTop) {
_edge = Top;
}
else if (onBottomLeft) {
_edge = BottomLeft;
}
else if (onBottomRight) {
_edge = BottomRight;
}
else if (onTopRight) {
_edge = TopRight;
}
else if (onTopLeft) {
_edge = TopLeft;
}
else {
_edge = None;
}
}









share|improve this question




















  • 2





    Show the complete error message, do not summarize it.

    – eyllanesc
    Nov 16 '18 at 22:03











  • The error is: "Invalid use of incomplete type 'class UI::FrameLess' "

    – Blazur
    Nov 17 '18 at 8:51
















0















I keep getting this error and I don't know why. It just says incomplete type of my class FrameLess. I don't think im missing including any files. I also want to specify that I have a mainwindow besides this widget and im trying to implement a UI form for my class FrameLess. Any help would be great. Thanks!



frameless.h



#ifndef FRAMELESS_H
#define FRAMELESS_H

#pragma once
#include <QtWidgets/QWidget>
#include <QtWidgets/QRubberBand>
#include <QtCore/QObject>
#include <QtCore/QEvent>
#include <QtCore/QRect>
#include <QtCore/QPoint>
#include <QtCore/Qt>
#include <QtGui/QHoverEvent>
#include <QtGui/QMouseEvent>
#include <QMainWindow>

namespace Ui {
class FrameLess;
}


class FrameLess : public QObject {
Q_OBJECT

public:
enum Edge {
None = 0x0,
Left = 0x1,
Top = 0x2,
Right = 0x4,
Bottom = 0x8,
TopLeft = 0x10,
TopRight = 0x20,
BottomLeft = 0x40,
BottomRight = 0x80,
};
Q_ENUM(Edge);
Q_DECLARE_FLAGS(Edges, Edge);

FrameLess(QWidget *target);

void setBorderWidth(int w) {
_borderWidth = w;
}
int borderWidth() const {
return _borderWidth;
}

protected:
bool eventFilter(QObject *o, QEvent *e) override;
void mouseHover(QHoverEvent*);
void mouseLeave(QEvent*);
void mousePress(QMouseEvent*);
void mouseRealese(QMouseEvent*);
void mouseMove(QMouseEvent*);
void updateCursorShape(const QPoint &);
void calculateCursorPosition(const QPoint &, const QRect &, Edges &);

private:
QWidget *_target = nullptr;
QRubberBand *_rubberband = nullptr;
bool _cursorchanged;
bool _leftButtonPressed;
Edges _mousePress = Edge::None;
Edges _mouseMove = Edge::None;
int _borderWidth;
Ui::FrameLess *ui;
QPoint _dragPos;
bool _dragStart = false;



};

Q_DECLARE_OPERATORS_FOR_FLAGS(FrameLess::Edges);
#endif


frameless.cpp:



#include "frameless.h"
#include "ui_frameless.h"

FrameLess::FrameLess(QWidget *target) :_target(target),_cursorchanged(false),_leftButtonPressed(false),_borderWidth(5),_dragPos(QPoint()), ui(new Ui::FrameLess)
{
// ui->setup(this);
_target->setMouseTracking(true);
_target->setWindowFlags(Qt::FramelessWindowHint);
_target->setAttribute(Qt::WA_Hover);
_target->installEventFilter(this);
_rubberband = new QRubberBand(QRubberBand::Rectangle);
}

bool FrameLess::eventFilter(QObject *o, QEvent*e) {
if (e->type() == QEvent::MouseMove ||
e->type() == QEvent::HoverMove ||
e->type() == QEvent::Leave ||
e->type() == QEvent::MouseButtonPress ||
e->type() == QEvent::MouseButtonRelease) {

switch (e->type()) {
case QEvent::MouseMove:
mouseMove(static_cast<QMouseEvent*>(e));
return true;
break;
case QEvent::HoverMove:
mouseHover(static_cast<QHoverEvent*>(e));
return true;
break;
case QEvent::Leave:
mouseLeave(e);
return true;
break;
case QEvent::MouseButtonPress:
mousePress(static_cast<QMouseEvent*>(e));
return true;
break;
case QEvent::MouseButtonRelease:
mouseRealese(static_cast<QMouseEvent*>(e));
return true;
break;
}
}
else {
return _target->eventFilter(o, e);
}
}

void FrameLess::mouseHover(QHoverEvent *e) {
updateCursorShape(_target->mapToGlobal(e->pos()));
}

void FrameLess::mouseLeave(QEvent *e) {
if (!_leftButtonPressed) {
_target->unsetCursor();
}
}

void FrameLess::mousePress(QMouseEvent *e) {
if (e->button() & Qt::LeftButton) {
_leftButtonPressed = true;
calculateCursorPosition(e->globalPos(), _target->frameGeometry(), _mousePress);
if (!_mousePress.testFlag(Edge::None)) {
_rubberband->setGeometry(_target->frameGeometry());
}
if (_target->rect().marginsRemoved(QMargins(borderWidth(), borderWidth(), borderWidth(), borderWidth())).contains(e->pos())) {
_dragStart = true;
_dragPos = e->pos();
}
}
}

void FrameLess::mouseRealese(QMouseEvent *e) {
if (e->button() & Qt::LeftButton) {
_leftButtonPressed = false;
_dragStart = false;
}
}

void FrameLess::mouseMove(QMouseEvent *e) {
if (_leftButtonPressed) {
if (_dragStart) {
_target->move(_target->frameGeometry().topLeft() + (e->pos() - _dragPos));
}

if (!_mousePress.testFlag(Edge::None)) {
int left = _rubberband->frameGeometry().left();
int top = _rubberband->frameGeometry().top();
int right = _rubberband->frameGeometry().right();
int bottom = _rubberband->frameGeometry().bottom();
switch (_mousePress) {
case Edge::Top:
top = e->globalPos().y();
break;
case Edge::Bottom:
bottom = e->globalPos().y();
break;
case Edge::Left:
left = e->globalPos().x();
break;
case Edge::Right:
right = e->globalPos().x();
break;
case Edge::TopLeft:
top = e->globalPos().y();
left = e->globalPos().x();
break;
case Edge::TopRight:
right = e->globalPos().x();
top = e->globalPos().y();
break;
case Edge::BottomLeft:
bottom = e->globalPos().y();
left = e->globalPos().x();
break;
case Edge::BottomRight:
bottom = e->globalPos().y();
right = e->globalPos().x();
break;
}
QRect newRect(QPoint(left, top), QPoint(right, bottom));
if (newRect.width() < _target->minimumWidth()) {
left = _target->frameGeometry().x();
}
else if (newRect.height() < _target->minimumHeight()) {
top = _target->frameGeometry().y();
}
_target->setGeometry(QRect(QPoint(left, top), QPoint(right, bottom)));
_rubberband->setGeometry(QRect(QPoint(left, top), QPoint(right, bottom)));
}
}
else {
updateCursorShape(e->globalPos());
}
}

void FrameLess::updateCursorShape(const QPoint &pos) {
if (_target->isFullScreen() || _target->isMaximized()) {
if (_cursorchanged) {
_target->unsetCursor();
}
return;
}
if (!_leftButtonPressed) {
calculateCursorPosition(pos, _target->frameGeometry(), _mouseMove);
_cursorchanged = true;
if (_mouseMove.testFlag(Edge::Top) || _mouseMove.testFlag(Edge::Bottom)) {
_target->setCursor(Qt::SizeVerCursor);
}
else if (_mouseMove.testFlag(Edge::Left) || _mouseMove.testFlag(Edge::Right)) {
_target->setCursor(Qt::SizeHorCursor);
}
else if (_mouseMove.testFlag(Edge::TopLeft) || _mouseMove.testFlag(Edge::BottomRight)) {
_target->setCursor(Qt::SizeFDiagCursor);
}
else if (_mouseMove.testFlag(Edge::TopRight) || _mouseMove.testFlag(Edge::BottomLeft)) {
_target->setCursor(Qt::SizeBDiagCursor);
}
else if (_cursorchanged) {
_target->unsetCursor();
_cursorchanged = false;
}
}
}

void FrameLess::calculateCursorPosition(const QPoint &pos, const QRect &framerect, Edges &_edge) {
bool onLeft = pos.x() >= framerect.x() - _borderWidth && pos.x() <= framerect.x() + _borderWidth &&
pos.y() <= framerect.y() + framerect.height() - _borderWidth && pos.y() >= framerect.y() + _borderWidth;

bool onRight = pos.x() >= framerect.x() + framerect.width() - _borderWidth && pos.x() <= framerect.x() + framerect.width() &&
pos.y() >= framerect.y() + _borderWidth && pos.y() <= framerect.y() + framerect.height() - _borderWidth;

bool onBottom = pos.x() >= framerect.x() + _borderWidth && pos.x() <= framerect.x() + framerect.width() - _borderWidth &&
pos.y() >= framerect.y() + framerect.height() - _borderWidth && pos.y() <= framerect.y() + framerect.height();

bool onTop = pos.x() >= framerect.x() + _borderWidth && pos.x() <= framerect.x() + framerect.width() - _borderWidth &&
pos.y() >= framerect.y() && pos.y() <= framerect.y() + _borderWidth;

bool onBottomLeft = pos.x() <= framerect.x() + _borderWidth && pos.x() >= framerect.x() &&
pos.y() <= framerect.y() + framerect.height() && pos.y() >= framerect.y() + framerect.height() - _borderWidth;

bool onBottomRight = pos.x() >= framerect.x() + framerect.width() - _borderWidth && pos.x() <= framerect.x() + framerect.width() &&
pos.y() >= framerect.y() + framerect.height() - _borderWidth && pos.y() <= framerect.y() + framerect.height();

bool onTopRight = pos.x() >= framerect.x() + framerect.width() - _borderWidth && pos.x() <= framerect.x() + framerect.width() &&
pos.y() >= framerect.y() && pos.y() <= framerect.y() + _borderWidth;

bool onTopLeft = pos.x() >= framerect.x() && pos.x() <= framerect.x() + _borderWidth &&
pos.y() >= framerect.y() && pos.y() <= framerect.y() + _borderWidth;

if (onLeft) {
_edge = Left;
}
else if (onRight) {
_edge = Right;
}
else if (onBottom) {
_edge = Bottom;
}
else if (onTop) {
_edge = Top;
}
else if (onBottomLeft) {
_edge = BottomLeft;
}
else if (onBottomRight) {
_edge = BottomRight;
}
else if (onTopRight) {
_edge = TopRight;
}
else if (onTopLeft) {
_edge = TopLeft;
}
else {
_edge = None;
}
}









share|improve this question




















  • 2





    Show the complete error message, do not summarize it.

    – eyllanesc
    Nov 16 '18 at 22:03











  • The error is: "Invalid use of incomplete type 'class UI::FrameLess' "

    – Blazur
    Nov 17 '18 at 8:51














0












0








0








I keep getting this error and I don't know why. It just says incomplete type of my class FrameLess. I don't think im missing including any files. I also want to specify that I have a mainwindow besides this widget and im trying to implement a UI form for my class FrameLess. Any help would be great. Thanks!



frameless.h



#ifndef FRAMELESS_H
#define FRAMELESS_H

#pragma once
#include <QtWidgets/QWidget>
#include <QtWidgets/QRubberBand>
#include <QtCore/QObject>
#include <QtCore/QEvent>
#include <QtCore/QRect>
#include <QtCore/QPoint>
#include <QtCore/Qt>
#include <QtGui/QHoverEvent>
#include <QtGui/QMouseEvent>
#include <QMainWindow>

namespace Ui {
class FrameLess;
}


class FrameLess : public QObject {
Q_OBJECT

public:
enum Edge {
None = 0x0,
Left = 0x1,
Top = 0x2,
Right = 0x4,
Bottom = 0x8,
TopLeft = 0x10,
TopRight = 0x20,
BottomLeft = 0x40,
BottomRight = 0x80,
};
Q_ENUM(Edge);
Q_DECLARE_FLAGS(Edges, Edge);

FrameLess(QWidget *target);

void setBorderWidth(int w) {
_borderWidth = w;
}
int borderWidth() const {
return _borderWidth;
}

protected:
bool eventFilter(QObject *o, QEvent *e) override;
void mouseHover(QHoverEvent*);
void mouseLeave(QEvent*);
void mousePress(QMouseEvent*);
void mouseRealese(QMouseEvent*);
void mouseMove(QMouseEvent*);
void updateCursorShape(const QPoint &);
void calculateCursorPosition(const QPoint &, const QRect &, Edges &);

private:
QWidget *_target = nullptr;
QRubberBand *_rubberband = nullptr;
bool _cursorchanged;
bool _leftButtonPressed;
Edges _mousePress = Edge::None;
Edges _mouseMove = Edge::None;
int _borderWidth;
Ui::FrameLess *ui;
QPoint _dragPos;
bool _dragStart = false;



};

Q_DECLARE_OPERATORS_FOR_FLAGS(FrameLess::Edges);
#endif


frameless.cpp:



#include "frameless.h"
#include "ui_frameless.h"

FrameLess::FrameLess(QWidget *target) :_target(target),_cursorchanged(false),_leftButtonPressed(false),_borderWidth(5),_dragPos(QPoint()), ui(new Ui::FrameLess)
{
// ui->setup(this);
_target->setMouseTracking(true);
_target->setWindowFlags(Qt::FramelessWindowHint);
_target->setAttribute(Qt::WA_Hover);
_target->installEventFilter(this);
_rubberband = new QRubberBand(QRubberBand::Rectangle);
}

bool FrameLess::eventFilter(QObject *o, QEvent*e) {
if (e->type() == QEvent::MouseMove ||
e->type() == QEvent::HoverMove ||
e->type() == QEvent::Leave ||
e->type() == QEvent::MouseButtonPress ||
e->type() == QEvent::MouseButtonRelease) {

switch (e->type()) {
case QEvent::MouseMove:
mouseMove(static_cast<QMouseEvent*>(e));
return true;
break;
case QEvent::HoverMove:
mouseHover(static_cast<QHoverEvent*>(e));
return true;
break;
case QEvent::Leave:
mouseLeave(e);
return true;
break;
case QEvent::MouseButtonPress:
mousePress(static_cast<QMouseEvent*>(e));
return true;
break;
case QEvent::MouseButtonRelease:
mouseRealese(static_cast<QMouseEvent*>(e));
return true;
break;
}
}
else {
return _target->eventFilter(o, e);
}
}

void FrameLess::mouseHover(QHoverEvent *e) {
updateCursorShape(_target->mapToGlobal(e->pos()));
}

void FrameLess::mouseLeave(QEvent *e) {
if (!_leftButtonPressed) {
_target->unsetCursor();
}
}

void FrameLess::mousePress(QMouseEvent *e) {
if (e->button() & Qt::LeftButton) {
_leftButtonPressed = true;
calculateCursorPosition(e->globalPos(), _target->frameGeometry(), _mousePress);
if (!_mousePress.testFlag(Edge::None)) {
_rubberband->setGeometry(_target->frameGeometry());
}
if (_target->rect().marginsRemoved(QMargins(borderWidth(), borderWidth(), borderWidth(), borderWidth())).contains(e->pos())) {
_dragStart = true;
_dragPos = e->pos();
}
}
}

void FrameLess::mouseRealese(QMouseEvent *e) {
if (e->button() & Qt::LeftButton) {
_leftButtonPressed = false;
_dragStart = false;
}
}

void FrameLess::mouseMove(QMouseEvent *e) {
if (_leftButtonPressed) {
if (_dragStart) {
_target->move(_target->frameGeometry().topLeft() + (e->pos() - _dragPos));
}

if (!_mousePress.testFlag(Edge::None)) {
int left = _rubberband->frameGeometry().left();
int top = _rubberband->frameGeometry().top();
int right = _rubberband->frameGeometry().right();
int bottom = _rubberband->frameGeometry().bottom();
switch (_mousePress) {
case Edge::Top:
top = e->globalPos().y();
break;
case Edge::Bottom:
bottom = e->globalPos().y();
break;
case Edge::Left:
left = e->globalPos().x();
break;
case Edge::Right:
right = e->globalPos().x();
break;
case Edge::TopLeft:
top = e->globalPos().y();
left = e->globalPos().x();
break;
case Edge::TopRight:
right = e->globalPos().x();
top = e->globalPos().y();
break;
case Edge::BottomLeft:
bottom = e->globalPos().y();
left = e->globalPos().x();
break;
case Edge::BottomRight:
bottom = e->globalPos().y();
right = e->globalPos().x();
break;
}
QRect newRect(QPoint(left, top), QPoint(right, bottom));
if (newRect.width() < _target->minimumWidth()) {
left = _target->frameGeometry().x();
}
else if (newRect.height() < _target->minimumHeight()) {
top = _target->frameGeometry().y();
}
_target->setGeometry(QRect(QPoint(left, top), QPoint(right, bottom)));
_rubberband->setGeometry(QRect(QPoint(left, top), QPoint(right, bottom)));
}
}
else {
updateCursorShape(e->globalPos());
}
}

void FrameLess::updateCursorShape(const QPoint &pos) {
if (_target->isFullScreen() || _target->isMaximized()) {
if (_cursorchanged) {
_target->unsetCursor();
}
return;
}
if (!_leftButtonPressed) {
calculateCursorPosition(pos, _target->frameGeometry(), _mouseMove);
_cursorchanged = true;
if (_mouseMove.testFlag(Edge::Top) || _mouseMove.testFlag(Edge::Bottom)) {
_target->setCursor(Qt::SizeVerCursor);
}
else if (_mouseMove.testFlag(Edge::Left) || _mouseMove.testFlag(Edge::Right)) {
_target->setCursor(Qt::SizeHorCursor);
}
else if (_mouseMove.testFlag(Edge::TopLeft) || _mouseMove.testFlag(Edge::BottomRight)) {
_target->setCursor(Qt::SizeFDiagCursor);
}
else if (_mouseMove.testFlag(Edge::TopRight) || _mouseMove.testFlag(Edge::BottomLeft)) {
_target->setCursor(Qt::SizeBDiagCursor);
}
else if (_cursorchanged) {
_target->unsetCursor();
_cursorchanged = false;
}
}
}

void FrameLess::calculateCursorPosition(const QPoint &pos, const QRect &framerect, Edges &_edge) {
bool onLeft = pos.x() >= framerect.x() - _borderWidth && pos.x() <= framerect.x() + _borderWidth &&
pos.y() <= framerect.y() + framerect.height() - _borderWidth && pos.y() >= framerect.y() + _borderWidth;

bool onRight = pos.x() >= framerect.x() + framerect.width() - _borderWidth && pos.x() <= framerect.x() + framerect.width() &&
pos.y() >= framerect.y() + _borderWidth && pos.y() <= framerect.y() + framerect.height() - _borderWidth;

bool onBottom = pos.x() >= framerect.x() + _borderWidth && pos.x() <= framerect.x() + framerect.width() - _borderWidth &&
pos.y() >= framerect.y() + framerect.height() - _borderWidth && pos.y() <= framerect.y() + framerect.height();

bool onTop = pos.x() >= framerect.x() + _borderWidth && pos.x() <= framerect.x() + framerect.width() - _borderWidth &&
pos.y() >= framerect.y() && pos.y() <= framerect.y() + _borderWidth;

bool onBottomLeft = pos.x() <= framerect.x() + _borderWidth && pos.x() >= framerect.x() &&
pos.y() <= framerect.y() + framerect.height() && pos.y() >= framerect.y() + framerect.height() - _borderWidth;

bool onBottomRight = pos.x() >= framerect.x() + framerect.width() - _borderWidth && pos.x() <= framerect.x() + framerect.width() &&
pos.y() >= framerect.y() + framerect.height() - _borderWidth && pos.y() <= framerect.y() + framerect.height();

bool onTopRight = pos.x() >= framerect.x() + framerect.width() - _borderWidth && pos.x() <= framerect.x() + framerect.width() &&
pos.y() >= framerect.y() && pos.y() <= framerect.y() + _borderWidth;

bool onTopLeft = pos.x() >= framerect.x() && pos.x() <= framerect.x() + _borderWidth &&
pos.y() >= framerect.y() && pos.y() <= framerect.y() + _borderWidth;

if (onLeft) {
_edge = Left;
}
else if (onRight) {
_edge = Right;
}
else if (onBottom) {
_edge = Bottom;
}
else if (onTop) {
_edge = Top;
}
else if (onBottomLeft) {
_edge = BottomLeft;
}
else if (onBottomRight) {
_edge = BottomRight;
}
else if (onTopRight) {
_edge = TopRight;
}
else if (onTopLeft) {
_edge = TopLeft;
}
else {
_edge = None;
}
}









share|improve this question
















I keep getting this error and I don't know why. It just says incomplete type of my class FrameLess. I don't think im missing including any files. I also want to specify that I have a mainwindow besides this widget and im trying to implement a UI form for my class FrameLess. Any help would be great. Thanks!



frameless.h



#ifndef FRAMELESS_H
#define FRAMELESS_H

#pragma once
#include <QtWidgets/QWidget>
#include <QtWidgets/QRubberBand>
#include <QtCore/QObject>
#include <QtCore/QEvent>
#include <QtCore/QRect>
#include <QtCore/QPoint>
#include <QtCore/Qt>
#include <QtGui/QHoverEvent>
#include <QtGui/QMouseEvent>
#include <QMainWindow>

namespace Ui {
class FrameLess;
}


class FrameLess : public QObject {
Q_OBJECT

public:
enum Edge {
None = 0x0,
Left = 0x1,
Top = 0x2,
Right = 0x4,
Bottom = 0x8,
TopLeft = 0x10,
TopRight = 0x20,
BottomLeft = 0x40,
BottomRight = 0x80,
};
Q_ENUM(Edge);
Q_DECLARE_FLAGS(Edges, Edge);

FrameLess(QWidget *target);

void setBorderWidth(int w) {
_borderWidth = w;
}
int borderWidth() const {
return _borderWidth;
}

protected:
bool eventFilter(QObject *o, QEvent *e) override;
void mouseHover(QHoverEvent*);
void mouseLeave(QEvent*);
void mousePress(QMouseEvent*);
void mouseRealese(QMouseEvent*);
void mouseMove(QMouseEvent*);
void updateCursorShape(const QPoint &);
void calculateCursorPosition(const QPoint &, const QRect &, Edges &);

private:
QWidget *_target = nullptr;
QRubberBand *_rubberband = nullptr;
bool _cursorchanged;
bool _leftButtonPressed;
Edges _mousePress = Edge::None;
Edges _mouseMove = Edge::None;
int _borderWidth;
Ui::FrameLess *ui;
QPoint _dragPos;
bool _dragStart = false;



};

Q_DECLARE_OPERATORS_FOR_FLAGS(FrameLess::Edges);
#endif


frameless.cpp:



#include "frameless.h"
#include "ui_frameless.h"

FrameLess::FrameLess(QWidget *target) :_target(target),_cursorchanged(false),_leftButtonPressed(false),_borderWidth(5),_dragPos(QPoint()), ui(new Ui::FrameLess)
{
// ui->setup(this);
_target->setMouseTracking(true);
_target->setWindowFlags(Qt::FramelessWindowHint);
_target->setAttribute(Qt::WA_Hover);
_target->installEventFilter(this);
_rubberband = new QRubberBand(QRubberBand::Rectangle);
}

bool FrameLess::eventFilter(QObject *o, QEvent*e) {
if (e->type() == QEvent::MouseMove ||
e->type() == QEvent::HoverMove ||
e->type() == QEvent::Leave ||
e->type() == QEvent::MouseButtonPress ||
e->type() == QEvent::MouseButtonRelease) {

switch (e->type()) {
case QEvent::MouseMove:
mouseMove(static_cast<QMouseEvent*>(e));
return true;
break;
case QEvent::HoverMove:
mouseHover(static_cast<QHoverEvent*>(e));
return true;
break;
case QEvent::Leave:
mouseLeave(e);
return true;
break;
case QEvent::MouseButtonPress:
mousePress(static_cast<QMouseEvent*>(e));
return true;
break;
case QEvent::MouseButtonRelease:
mouseRealese(static_cast<QMouseEvent*>(e));
return true;
break;
}
}
else {
return _target->eventFilter(o, e);
}
}

void FrameLess::mouseHover(QHoverEvent *e) {
updateCursorShape(_target->mapToGlobal(e->pos()));
}

void FrameLess::mouseLeave(QEvent *e) {
if (!_leftButtonPressed) {
_target->unsetCursor();
}
}

void FrameLess::mousePress(QMouseEvent *e) {
if (e->button() & Qt::LeftButton) {
_leftButtonPressed = true;
calculateCursorPosition(e->globalPos(), _target->frameGeometry(), _mousePress);
if (!_mousePress.testFlag(Edge::None)) {
_rubberband->setGeometry(_target->frameGeometry());
}
if (_target->rect().marginsRemoved(QMargins(borderWidth(), borderWidth(), borderWidth(), borderWidth())).contains(e->pos())) {
_dragStart = true;
_dragPos = e->pos();
}
}
}

void FrameLess::mouseRealese(QMouseEvent *e) {
if (e->button() & Qt::LeftButton) {
_leftButtonPressed = false;
_dragStart = false;
}
}

void FrameLess::mouseMove(QMouseEvent *e) {
if (_leftButtonPressed) {
if (_dragStart) {
_target->move(_target->frameGeometry().topLeft() + (e->pos() - _dragPos));
}

if (!_mousePress.testFlag(Edge::None)) {
int left = _rubberband->frameGeometry().left();
int top = _rubberband->frameGeometry().top();
int right = _rubberband->frameGeometry().right();
int bottom = _rubberband->frameGeometry().bottom();
switch (_mousePress) {
case Edge::Top:
top = e->globalPos().y();
break;
case Edge::Bottom:
bottom = e->globalPos().y();
break;
case Edge::Left:
left = e->globalPos().x();
break;
case Edge::Right:
right = e->globalPos().x();
break;
case Edge::TopLeft:
top = e->globalPos().y();
left = e->globalPos().x();
break;
case Edge::TopRight:
right = e->globalPos().x();
top = e->globalPos().y();
break;
case Edge::BottomLeft:
bottom = e->globalPos().y();
left = e->globalPos().x();
break;
case Edge::BottomRight:
bottom = e->globalPos().y();
right = e->globalPos().x();
break;
}
QRect newRect(QPoint(left, top), QPoint(right, bottom));
if (newRect.width() < _target->minimumWidth()) {
left = _target->frameGeometry().x();
}
else if (newRect.height() < _target->minimumHeight()) {
top = _target->frameGeometry().y();
}
_target->setGeometry(QRect(QPoint(left, top), QPoint(right, bottom)));
_rubberband->setGeometry(QRect(QPoint(left, top), QPoint(right, bottom)));
}
}
else {
updateCursorShape(e->globalPos());
}
}

void FrameLess::updateCursorShape(const QPoint &pos) {
if (_target->isFullScreen() || _target->isMaximized()) {
if (_cursorchanged) {
_target->unsetCursor();
}
return;
}
if (!_leftButtonPressed) {
calculateCursorPosition(pos, _target->frameGeometry(), _mouseMove);
_cursorchanged = true;
if (_mouseMove.testFlag(Edge::Top) || _mouseMove.testFlag(Edge::Bottom)) {
_target->setCursor(Qt::SizeVerCursor);
}
else if (_mouseMove.testFlag(Edge::Left) || _mouseMove.testFlag(Edge::Right)) {
_target->setCursor(Qt::SizeHorCursor);
}
else if (_mouseMove.testFlag(Edge::TopLeft) || _mouseMove.testFlag(Edge::BottomRight)) {
_target->setCursor(Qt::SizeFDiagCursor);
}
else if (_mouseMove.testFlag(Edge::TopRight) || _mouseMove.testFlag(Edge::BottomLeft)) {
_target->setCursor(Qt::SizeBDiagCursor);
}
else if (_cursorchanged) {
_target->unsetCursor();
_cursorchanged = false;
}
}
}

void FrameLess::calculateCursorPosition(const QPoint &pos, const QRect &framerect, Edges &_edge) {
bool onLeft = pos.x() >= framerect.x() - _borderWidth && pos.x() <= framerect.x() + _borderWidth &&
pos.y() <= framerect.y() + framerect.height() - _borderWidth && pos.y() >= framerect.y() + _borderWidth;

bool onRight = pos.x() >= framerect.x() + framerect.width() - _borderWidth && pos.x() <= framerect.x() + framerect.width() &&
pos.y() >= framerect.y() + _borderWidth && pos.y() <= framerect.y() + framerect.height() - _borderWidth;

bool onBottom = pos.x() >= framerect.x() + _borderWidth && pos.x() <= framerect.x() + framerect.width() - _borderWidth &&
pos.y() >= framerect.y() + framerect.height() - _borderWidth && pos.y() <= framerect.y() + framerect.height();

bool onTop = pos.x() >= framerect.x() + _borderWidth && pos.x() <= framerect.x() + framerect.width() - _borderWidth &&
pos.y() >= framerect.y() && pos.y() <= framerect.y() + _borderWidth;

bool onBottomLeft = pos.x() <= framerect.x() + _borderWidth && pos.x() >= framerect.x() &&
pos.y() <= framerect.y() + framerect.height() && pos.y() >= framerect.y() + framerect.height() - _borderWidth;

bool onBottomRight = pos.x() >= framerect.x() + framerect.width() - _borderWidth && pos.x() <= framerect.x() + framerect.width() &&
pos.y() >= framerect.y() + framerect.height() - _borderWidth && pos.y() <= framerect.y() + framerect.height();

bool onTopRight = pos.x() >= framerect.x() + framerect.width() - _borderWidth && pos.x() <= framerect.x() + framerect.width() &&
pos.y() >= framerect.y() && pos.y() <= framerect.y() + _borderWidth;

bool onTopLeft = pos.x() >= framerect.x() && pos.x() <= framerect.x() + _borderWidth &&
pos.y() >= framerect.y() && pos.y() <= framerect.y() + _borderWidth;

if (onLeft) {
_edge = Left;
}
else if (onRight) {
_edge = Right;
}
else if (onBottom) {
_edge = Bottom;
}
else if (onTop) {
_edge = Top;
}
else if (onBottomLeft) {
_edge = BottomLeft;
}
else if (onBottomRight) {
_edge = BottomRight;
}
else if (onTopRight) {
_edge = TopRight;
}
else if (onTopLeft) {
_edge = TopLeft;
}
else {
_edge = None;
}
}






c++ qt class user-interface






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '18 at 5:50









Per Lundberg

1,67712030




1,67712030










asked Nov 16 '18 at 20:41









BlazurBlazur

34




34








  • 2





    Show the complete error message, do not summarize it.

    – eyllanesc
    Nov 16 '18 at 22:03











  • The error is: "Invalid use of incomplete type 'class UI::FrameLess' "

    – Blazur
    Nov 17 '18 at 8:51














  • 2





    Show the complete error message, do not summarize it.

    – eyllanesc
    Nov 16 '18 at 22:03











  • The error is: "Invalid use of incomplete type 'class UI::FrameLess' "

    – Blazur
    Nov 17 '18 at 8:51








2




2





Show the complete error message, do not summarize it.

– eyllanesc
Nov 16 '18 at 22:03





Show the complete error message, do not summarize it.

– eyllanesc
Nov 16 '18 at 22:03













The error is: "Invalid use of incomplete type 'class UI::FrameLess' "

– Blazur
Nov 17 '18 at 8:51





The error is: "Invalid use of incomplete type 'class UI::FrameLess' "

– Blazur
Nov 17 '18 at 8:51












1 Answer
1






active

oldest

votes


















0














I tried this by recreating a simple project and copying in your code, making it a "Qt Designer Form Class" (which I think you also did), and recreated the same error as you did.



But, looking at the code sample, this is not really intended to be a QDialog but rather a QObject, i.e. a class deriving from the main Qt base class (QObject). So it should not be used that way.



I looked at the code and saw these lines in the constructor:



FrameLess::FrameLess(QWidget *target) :_target(target),_cursorchanged(false),_leftButtonPressed(false),_borderWidth(5),_dragPos(QPoint()), ui(new Ui::FrameLess)
{
// ui->setup(this);
_target->setMouseTracking(true);
_target->setWindowFlags(Qt::FramelessWindowHint);
_target->setAttribute(Qt::WA_Hover);
_target->installEventFilter(this);
_rubberband = new QRubberBand(QRubberBand::Rectangle);
}


As can be seen, this class takes in a target widget and modifies this widget, making it frameless (by e.g. setting the according window flags, attributes etc.). So the proper use case would be something like this, in the class where you want it to be used:



MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

new FrameLess(this);
}


The constructor call (new Frameless(this)) will modify the object that you pass to it in this way.





So, to get your example working, either recreate it in Qt Creator as a plain QObject-derived class, or to just do a quick test, remove from this part of the constructor:



FrameLess::FrameLess(QWidget *target) :_target(target),_cursorchanged(false),_leftButtonPressed(false),_borderWidth(5),_dragPos(QPoint()), ui(new Ui::FrameLess)


...the , ui(new Ui::FrameLess) part there at the end. I.e. don't assign anything to the ui class member.



In the .h file, remove this part:



private:
QWidget *_target = nullptr;
QRubberBand *_rubberband = nullptr;
bool _cursorchanged;
bool _leftButtonPressed;
Edges _mousePress = Edge::None;
Edges _mouseMove = Edge::None;
int _borderWidth;
Ui::FrameLess *ui; // <- remove this
QPoint _dragPos;
bool _dragStart = false;


By doing these changes, I could get your example working, but it's probably best to recreate it/delete the frameless.ui dialog from your project - it isn't used anyway, so it's best to just remove it.



Hope this helps! :-)






share|improve this answer
























  • Thank you ! But I need the frameless.ui so that i can edit the user interface. I want a resizeable transparent frameless window, with a .ui file so i can add buttons and stuff to it.

    – Blazur
    Nov 17 '18 at 20:21













  • Yes. Please re-read my answer. You create the window with the .ui file and all that, then from the constructor in your window class, call new FrameLess(this) - the FrameLess class will then adjust your window class instance so that it's frameless. You could perhaps also merge the content from the FrameLess class into your UI class (like you tried), but it might require more changes so I suggest going with this approach at first.

    – Per Lundberg
    Nov 18 '18 at 21:25











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53345093%2fqt-error-invalid-use-of-incomplete-type-class-uiframeless%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I tried this by recreating a simple project and copying in your code, making it a "Qt Designer Form Class" (which I think you also did), and recreated the same error as you did.



But, looking at the code sample, this is not really intended to be a QDialog but rather a QObject, i.e. a class deriving from the main Qt base class (QObject). So it should not be used that way.



I looked at the code and saw these lines in the constructor:



FrameLess::FrameLess(QWidget *target) :_target(target),_cursorchanged(false),_leftButtonPressed(false),_borderWidth(5),_dragPos(QPoint()), ui(new Ui::FrameLess)
{
// ui->setup(this);
_target->setMouseTracking(true);
_target->setWindowFlags(Qt::FramelessWindowHint);
_target->setAttribute(Qt::WA_Hover);
_target->installEventFilter(this);
_rubberband = new QRubberBand(QRubberBand::Rectangle);
}


As can be seen, this class takes in a target widget and modifies this widget, making it frameless (by e.g. setting the according window flags, attributes etc.). So the proper use case would be something like this, in the class where you want it to be used:



MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

new FrameLess(this);
}


The constructor call (new Frameless(this)) will modify the object that you pass to it in this way.





So, to get your example working, either recreate it in Qt Creator as a plain QObject-derived class, or to just do a quick test, remove from this part of the constructor:



FrameLess::FrameLess(QWidget *target) :_target(target),_cursorchanged(false),_leftButtonPressed(false),_borderWidth(5),_dragPos(QPoint()), ui(new Ui::FrameLess)


...the , ui(new Ui::FrameLess) part there at the end. I.e. don't assign anything to the ui class member.



In the .h file, remove this part:



private:
QWidget *_target = nullptr;
QRubberBand *_rubberband = nullptr;
bool _cursorchanged;
bool _leftButtonPressed;
Edges _mousePress = Edge::None;
Edges _mouseMove = Edge::None;
int _borderWidth;
Ui::FrameLess *ui; // <- remove this
QPoint _dragPos;
bool _dragStart = false;


By doing these changes, I could get your example working, but it's probably best to recreate it/delete the frameless.ui dialog from your project - it isn't used anyway, so it's best to just remove it.



Hope this helps! :-)






share|improve this answer
























  • Thank you ! But I need the frameless.ui so that i can edit the user interface. I want a resizeable transparent frameless window, with a .ui file so i can add buttons and stuff to it.

    – Blazur
    Nov 17 '18 at 20:21













  • Yes. Please re-read my answer. You create the window with the .ui file and all that, then from the constructor in your window class, call new FrameLess(this) - the FrameLess class will then adjust your window class instance so that it's frameless. You could perhaps also merge the content from the FrameLess class into your UI class (like you tried), but it might require more changes so I suggest going with this approach at first.

    – Per Lundberg
    Nov 18 '18 at 21:25
















0














I tried this by recreating a simple project and copying in your code, making it a "Qt Designer Form Class" (which I think you also did), and recreated the same error as you did.



But, looking at the code sample, this is not really intended to be a QDialog but rather a QObject, i.e. a class deriving from the main Qt base class (QObject). So it should not be used that way.



I looked at the code and saw these lines in the constructor:



FrameLess::FrameLess(QWidget *target) :_target(target),_cursorchanged(false),_leftButtonPressed(false),_borderWidth(5),_dragPos(QPoint()), ui(new Ui::FrameLess)
{
// ui->setup(this);
_target->setMouseTracking(true);
_target->setWindowFlags(Qt::FramelessWindowHint);
_target->setAttribute(Qt::WA_Hover);
_target->installEventFilter(this);
_rubberband = new QRubberBand(QRubberBand::Rectangle);
}


As can be seen, this class takes in a target widget and modifies this widget, making it frameless (by e.g. setting the according window flags, attributes etc.). So the proper use case would be something like this, in the class where you want it to be used:



MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

new FrameLess(this);
}


The constructor call (new Frameless(this)) will modify the object that you pass to it in this way.





So, to get your example working, either recreate it in Qt Creator as a plain QObject-derived class, or to just do a quick test, remove from this part of the constructor:



FrameLess::FrameLess(QWidget *target) :_target(target),_cursorchanged(false),_leftButtonPressed(false),_borderWidth(5),_dragPos(QPoint()), ui(new Ui::FrameLess)


...the , ui(new Ui::FrameLess) part there at the end. I.e. don't assign anything to the ui class member.



In the .h file, remove this part:



private:
QWidget *_target = nullptr;
QRubberBand *_rubberband = nullptr;
bool _cursorchanged;
bool _leftButtonPressed;
Edges _mousePress = Edge::None;
Edges _mouseMove = Edge::None;
int _borderWidth;
Ui::FrameLess *ui; // <- remove this
QPoint _dragPos;
bool _dragStart = false;


By doing these changes, I could get your example working, but it's probably best to recreate it/delete the frameless.ui dialog from your project - it isn't used anyway, so it's best to just remove it.



Hope this helps! :-)






share|improve this answer
























  • Thank you ! But I need the frameless.ui so that i can edit the user interface. I want a resizeable transparent frameless window, with a .ui file so i can add buttons and stuff to it.

    – Blazur
    Nov 17 '18 at 20:21













  • Yes. Please re-read my answer. You create the window with the .ui file and all that, then from the constructor in your window class, call new FrameLess(this) - the FrameLess class will then adjust your window class instance so that it's frameless. You could perhaps also merge the content from the FrameLess class into your UI class (like you tried), but it might require more changes so I suggest going with this approach at first.

    – Per Lundberg
    Nov 18 '18 at 21:25














0












0








0







I tried this by recreating a simple project and copying in your code, making it a "Qt Designer Form Class" (which I think you also did), and recreated the same error as you did.



But, looking at the code sample, this is not really intended to be a QDialog but rather a QObject, i.e. a class deriving from the main Qt base class (QObject). So it should not be used that way.



I looked at the code and saw these lines in the constructor:



FrameLess::FrameLess(QWidget *target) :_target(target),_cursorchanged(false),_leftButtonPressed(false),_borderWidth(5),_dragPos(QPoint()), ui(new Ui::FrameLess)
{
// ui->setup(this);
_target->setMouseTracking(true);
_target->setWindowFlags(Qt::FramelessWindowHint);
_target->setAttribute(Qt::WA_Hover);
_target->installEventFilter(this);
_rubberband = new QRubberBand(QRubberBand::Rectangle);
}


As can be seen, this class takes in a target widget and modifies this widget, making it frameless (by e.g. setting the according window flags, attributes etc.). So the proper use case would be something like this, in the class where you want it to be used:



MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

new FrameLess(this);
}


The constructor call (new Frameless(this)) will modify the object that you pass to it in this way.





So, to get your example working, either recreate it in Qt Creator as a plain QObject-derived class, or to just do a quick test, remove from this part of the constructor:



FrameLess::FrameLess(QWidget *target) :_target(target),_cursorchanged(false),_leftButtonPressed(false),_borderWidth(5),_dragPos(QPoint()), ui(new Ui::FrameLess)


...the , ui(new Ui::FrameLess) part there at the end. I.e. don't assign anything to the ui class member.



In the .h file, remove this part:



private:
QWidget *_target = nullptr;
QRubberBand *_rubberband = nullptr;
bool _cursorchanged;
bool _leftButtonPressed;
Edges _mousePress = Edge::None;
Edges _mouseMove = Edge::None;
int _borderWidth;
Ui::FrameLess *ui; // <- remove this
QPoint _dragPos;
bool _dragStart = false;


By doing these changes, I could get your example working, but it's probably best to recreate it/delete the frameless.ui dialog from your project - it isn't used anyway, so it's best to just remove it.



Hope this helps! :-)






share|improve this answer













I tried this by recreating a simple project and copying in your code, making it a "Qt Designer Form Class" (which I think you also did), and recreated the same error as you did.



But, looking at the code sample, this is not really intended to be a QDialog but rather a QObject, i.e. a class deriving from the main Qt base class (QObject). So it should not be used that way.



I looked at the code and saw these lines in the constructor:



FrameLess::FrameLess(QWidget *target) :_target(target),_cursorchanged(false),_leftButtonPressed(false),_borderWidth(5),_dragPos(QPoint()), ui(new Ui::FrameLess)
{
// ui->setup(this);
_target->setMouseTracking(true);
_target->setWindowFlags(Qt::FramelessWindowHint);
_target->setAttribute(Qt::WA_Hover);
_target->installEventFilter(this);
_rubberband = new QRubberBand(QRubberBand::Rectangle);
}


As can be seen, this class takes in a target widget and modifies this widget, making it frameless (by e.g. setting the according window flags, attributes etc.). So the proper use case would be something like this, in the class where you want it to be used:



MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

new FrameLess(this);
}


The constructor call (new Frameless(this)) will modify the object that you pass to it in this way.





So, to get your example working, either recreate it in Qt Creator as a plain QObject-derived class, or to just do a quick test, remove from this part of the constructor:



FrameLess::FrameLess(QWidget *target) :_target(target),_cursorchanged(false),_leftButtonPressed(false),_borderWidth(5),_dragPos(QPoint()), ui(new Ui::FrameLess)


...the , ui(new Ui::FrameLess) part there at the end. I.e. don't assign anything to the ui class member.



In the .h file, remove this part:



private:
QWidget *_target = nullptr;
QRubberBand *_rubberband = nullptr;
bool _cursorchanged;
bool _leftButtonPressed;
Edges _mousePress = Edge::None;
Edges _mouseMove = Edge::None;
int _borderWidth;
Ui::FrameLess *ui; // <- remove this
QPoint _dragPos;
bool _dragStart = false;


By doing these changes, I could get your example working, but it's probably best to recreate it/delete the frameless.ui dialog from your project - it isn't used anyway, so it's best to just remove it.



Hope this helps! :-)







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 17 '18 at 20:03









Per LundbergPer Lundberg

1,67712030




1,67712030













  • Thank you ! But I need the frameless.ui so that i can edit the user interface. I want a resizeable transparent frameless window, with a .ui file so i can add buttons and stuff to it.

    – Blazur
    Nov 17 '18 at 20:21













  • Yes. Please re-read my answer. You create the window with the .ui file and all that, then from the constructor in your window class, call new FrameLess(this) - the FrameLess class will then adjust your window class instance so that it's frameless. You could perhaps also merge the content from the FrameLess class into your UI class (like you tried), but it might require more changes so I suggest going with this approach at first.

    – Per Lundberg
    Nov 18 '18 at 21:25



















  • Thank you ! But I need the frameless.ui so that i can edit the user interface. I want a resizeable transparent frameless window, with a .ui file so i can add buttons and stuff to it.

    – Blazur
    Nov 17 '18 at 20:21













  • Yes. Please re-read my answer. You create the window with the .ui file and all that, then from the constructor in your window class, call new FrameLess(this) - the FrameLess class will then adjust your window class instance so that it's frameless. You could perhaps also merge the content from the FrameLess class into your UI class (like you tried), but it might require more changes so I suggest going with this approach at first.

    – Per Lundberg
    Nov 18 '18 at 21:25

















Thank you ! But I need the frameless.ui so that i can edit the user interface. I want a resizeable transparent frameless window, with a .ui file so i can add buttons and stuff to it.

– Blazur
Nov 17 '18 at 20:21







Thank you ! But I need the frameless.ui so that i can edit the user interface. I want a resizeable transparent frameless window, with a .ui file so i can add buttons and stuff to it.

– Blazur
Nov 17 '18 at 20:21















Yes. Please re-read my answer. You create the window with the .ui file and all that, then from the constructor in your window class, call new FrameLess(this) - the FrameLess class will then adjust your window class instance so that it's frameless. You could perhaps also merge the content from the FrameLess class into your UI class (like you tried), but it might require more changes so I suggest going with this approach at first.

– Per Lundberg
Nov 18 '18 at 21:25





Yes. Please re-read my answer. You create the window with the .ui file and all that, then from the constructor in your window class, call new FrameLess(this) - the FrameLess class will then adjust your window class instance so that it's frameless. You could perhaps also merge the content from the FrameLess class into your UI class (like you tried), but it might require more changes so I suggest going with this approach at first.

– Per Lundberg
Nov 18 '18 at 21:25


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53345093%2fqt-error-invalid-use-of-incomplete-type-class-uiframeless%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?