Wie realisiere ich sowas? Im Qt-Designer?
MfG
Code: Alles auswählen
Xgq2Titlebar::Xgq2Titlebar(QWidget *p) : QWidget(p) {
moving = false;
active = false;
setBackgroundMode(NoBackground);
}
void Xgq2Titlebar::setPixmapActive(int pixId) { nActiveId = pixId; }
void Xgq2Titlebar::setPixmapInactive(int pixId) { nInactiveId = pixId; }
void Xgq2Titlebar::setState(bool state) { active = state; update(); }
void Xgq2Titlebar::paintEvent(QPaintEvent *) { Xgq2Modeller::instance()->bltTo(getPixmapId(), this, 0, 0); }
int Xgq2Titlebar::getPixmapId() {
if (active)
return nActiveId;
else
return nInactiveId;
}
void Xgq2Titlebar::mousePressEvent(QMouseEvent * e) {
if (e->button() != RightButton) {
if (!moving) {
moving = true;
mDragStart = e->pos();
mLastPos = e->globalPos();
}
active = true;
update();
return;
}
}
void Xgq2Titlebar::mouseDoubleClickEvent(QMouseEvent *) { emit(shaded()); }
void Xgq2Titlebar::mouseReleaseEvent(QMouseEvent * e) {
if (e->button() != RightButton) {
moving = false;
update();
return;
}
}
void Xgq2Titlebar::mouseMoveEvent(QMouseEvent * e) {
QPoint diff = e->globalPos() - mLastPos;
if (abs(diff.x()) > 10 || abs(diff.y()) > 10) {
// Moving starts only, when passing a drag border
moving = true;
}
if (moving)
parentWidget()->move(e->globalPos() - mDragStart);
}