Results 1 to 4 of 4

Thread: setWindowstate() not working after moving window when maximized???

  1. #1
    Join Date
    Apr 2017
    Posts
    21
    Qt products
    Qt5
    Platforms
    Windows

    Default setWindowstate() not working after moving window when maximized???

    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:

    Qt Code:
    1. void myApp::tmaxout()
    2. {
    3.  
    4. qDebug() << "Getting the size message";
    5. qDebug("%i",windowState());
    6.  
    7.  
    8. setWindowState(windowState() ^ Qt::WindowMaximized);
    9.  
    10.  
    11. if (windowState() == 0)
    12. {
    13. ui->centralWidget->setStyleSheet("QWidget#centralWidget { border: 12px solid black; border-radius:24px;}");
    14. }
    15. else
    16. {
    17. ui->centralWidget->setStyleSheet("QWidget#centralWidget {border: 12px solid black;}");
    18. // setAttribute(Qt::WA_NativeWindow);
    19. };
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: setWindowstate() not working after moving window when maximized???

    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?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Apr 2017
    Posts
    21
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: setWindowstate() not working after moving window when maximized???

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: setWindowstate() not working after moving window when maximized???

    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).
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 1
    Last Post: 7th April 2013, 00:26
  2. Replies: 2
    Last Post: 10th August 2012, 08:15
  3. Resizing a maximized, custom-frame window
    By Claymore in forum Qt Programming
    Replies: 9
    Last Post: 24th November 2010, 18:17
  4. problem: Window moves on click when maximized
    By Toshikazu in forum Qt Programming
    Replies: 3
    Last Post: 30th January 2010, 22:22
  5. Frustrated trying to get maximized window.
    By Doug Broadwell in forum Qt Programming
    Replies: 4
    Last Post: 6th February 2009, 06:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.