PDA

View Full Version : setWindowstate() not working after moving window when maximized???



davidm71
26th April 2017, 13:48
I'm sure this is probably related to how events are handled but what is going on is I have a custom titlebar and class that reacts to double clicks allowing the qmainwindow to maximize when double click message is picked up and then go to a normal state when double clicked again. That works as intended. The problem is when I move or reposition the window by dragging via mouse the first double click is ignored. It takes another double click event to set the window back to a normal state. Here is some code:



void myApp::tmaxout()
{

qDebug() << "Getting the size message";
qDebug("%i",windowState());


setWindowState(windowState() ^ Qt::WindowMaximized);


if (windowState() == 0)
{
ui->centralWidget->setStyleSheet("QWidget#centralWidget { border: 12px solid black; border-radius:24px;}");
}
else
{
ui->centralWidget->setStyleSheet("QWidget#centralWidget {border: 12px solid black;}");
// setAttribute(Qt::WA_NativeWindow);
};


My tmaxout method is a private slot that gets called by my custom titlebar class by emiting a custom signal that I have verified in QDebug after the doubleclick is sent out. So no problem passing messages.

Thanks

high_flyer
27th April 2017, 01:05
I don't get your xor operation with the window state.
Xor would mean that if the state bit 'maximized' it set it will unset it.
Is that your intention?
To me this is badly readable code, it requires the reader to be very attentive and its easy to make a logical mistake.
If you want to toggle the maximized bit, you can simply set the bit inverted.
Do you want always to set maximized in this method or only when some condition is met, if so - which condition?
If you would to wrap line 8 in a method, which descriptive name would you give that method?

davidm71
27th April 2017, 02:38
Yes I am sorry for not being clear. My intention is to toggle between windowstate 0 and 2 which corresponds to a normal (not maximized) window and maximized window. The condition being that the titlebar is double-clicked where the titlebar class sends a message to the main window class to toggle the window state. That part works. The problem is that if the window is dragged out of the maximized mode and then I try to double click to maximize it again it gets ignored on the first try. Not sure what is going on. Will figure it out.

high_flyer
27th April 2017, 11:29
Amm... to me your answer kinds of blends everything together and it makes it hard for me to understand what you are trying to do.
What you call "the condition" is not a condition effecting what tmaxout() does internally.
I meant, if you don't want to set the maximized bit *every time* in tmaxyout() under which condition do you want to set it?
At the moment your are not using any condition in tmaxout() for toggling the maximize bit.

I took it from your previous post that you have checked via debug output and confirmed that tmaxout() is always called when you double click - just the result of what it does is every second call, is that correct or did I misunderstand?
If this is correct, then it means that the maximized bit was already set when tmaxout() was called the first time. (remember it toggles the state, so if it was set, it will unset it in the first time which would explain the behavior you see).