PDA

View Full Version : Window customization



Kostanev
18th December 2007, 13:07
Hello there,
I have two questions:

1. How to remove this border from the main window:
http://elisa.kostanev.com/Qt/window_customization.jpg

2. How can I move my window from my "Title frame" ?
I'm trying with mouseMoveEvent, but my calculations are wrong.

Thanks to all.

jpn
18th December 2007, 13:15
See Qt::FramelessWindowHint (http://doc.trolltech.com/latest/qt.html#WindowType-enum)
See wiki article: Moving widgets

The Storm
12th August 2008, 15:45
Hello, I followed the tutorial, on first look seems to work fine but when I click on a some control like button or slider and I move the mouse the main window start to jump and the mouse is moved to the top left corner of the window. Any fix for this ? :)

The Storm
13th August 2008, 00:39
Anyone, please.

aamer4yu
13th August 2008, 05:36
Cant really tell without seeing what you are doing.
Can we see what are you doing ?

spirit
13th August 2008, 07:46
post some code, please.

jpn
13th August 2008, 11:29
The problem seems to be that QSlider basically always accepts mouse press events but ignores mouse move events in case the user pressed outside the slider handle. Furthermore, ignored events are propagated to the parent, which means that the window doesn't receive a press event but a move event directly, thus offset is not calculated and the window jumps to wrong location. One solution could be to subclass and ensure that appropriate events are accepted. I guess you wouldn't like to move the window by dragging from a slider.


void MySlider::mouseMoveEvent(QMouseEvent* event)
{
QSlider::mouseMoveEvent(event);
event->accept();
}

The Storm
13th August 2008, 11:52
Cant really tell without seeing what you are doing.
Can we see what are you doing ?

The code is in to the wiki page that the link is above, I do it in the very same way by subclassing QMainWindow.

@jpn Yes I don't want the window to move when I'm clicking some of the components like the slider, but if I inherit all of them I will not be able to use the Qt Designer at all. :(

jpn
13th August 2008, 13:01
but if I inherit all of them I will not be able to use the Qt Designer at all. :(
Actually you can (http://doc.trolltech.com/4.4/designer-using-custom-widgets.html#promoting-widgets) (check the link) but it won't be very convenient... :)

The Storm
13th August 2008, 13:46
Well maybe is possible some hack to ignore the move event if a press event hasn't been called ? :)

jpn
13th August 2008, 14:39
Well maybe is possible some hack to ignore the move event if a press event hasn't been called ? :)
Sure, that's another, maybe even better way. :)

The Storm
14th August 2008, 18:04
Done, it works perfect with just one more bool variable. :)
Here's the result of code


void mousePressEvent(QMouseEvent *event)
{
event->accept(); // do not propagate
if (isWindow())
offset = event->globalPos() - pos();
else
offset = event->pos();

MousePressEventCalled = true;
}

void mouseReleaseEvent(QMouseEvent *event)
{
event->accept(); // do not propagate
offset = QPoint();
MousePressEventCalled = false;
}

void mouseMoveEvent(QMouseEvent *event)
{
if (!MousePressEventCalled)
{
event->ignore();
return;
}

event->accept(); // do not propagate
if (isWindow())
move(event->globalPos() - offset);
else
move(mapToParent(event->pos() - offset));
}