QWidget form "sticked" on the left of QMainWindow. is possible?



  • Hello,
    i'm developing a UI with Qt4.8 and i have a little trouble with it:
    i've created a QMainWindow with many QPushButton inside a QGridLayout. When the user press one of this buttons, a QWidget Form is shown on the left of QMainWindow. When the user try to move the main window, i want that the position of QWidget Form (if it is visible) change according to the new position of the main window. The result is that the QWidget Form seems sticked on the left of QMainWindow. It is possible to set a "property" to do that?

    I also try to intercept the mousePressEvent of title bar but i know that the titlebar of QMainWindow is property of OS and so all the events is managed by the OS. So there is a way to handle this events by my code, without creating QMainWindow with FrameLess property and add a custom TitleBar to handle events inside it? Thanks a lot for all answers.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Do you mean something like a QDockWidget or a floating window ?



  • Thanks for your answer. My case is different than QDockWidget.
    I've created two different forms: one is QMainWindow that is visible on launch; the second is shown when a button on QMainWindow is pressed. The second form is outside QMainWindow and has his titlebar etc.

    So, when the user push this button, i want the second form to be "attached" on the left of QMainWindow (outside the mainwindow), and if the user move the QMainWindow, i want the second form to remain "attached" to QMainWindow and move according to the new position of mainwindow.


  • Lifetime Qt Champion

    You could use the moveEvent of your QMainWindow and update the geometry of your second widget to follow that main window.

    Hope it helps



  • I think "Qmmp":http://qt-apps.org/content/show.php/Qmmp?content=59218 does something similar with its windows.
    Take a look on their sources



  • [quote author="SGaist" date="1409957818"]You could use the moveEvent of your QMainWindow and update the geometry of your second widget to follow that main window.

    Hope it helps[/quote]

    I've already tried to reimplement the moveEvent of QMainWindow, but when the widget receives this event it is already at the new position: so, if i try to change the position of the second form, the result effect is very bad!

    [quote author="andreyc" date="1409985186"]I think "Qmmp":http://qt-apps.org/content/show.php/Qmmp?content=59218 does something similar with its windows.
    Take a look on their sources[/quote]

    I'll take a look, thanks very much!



  • i decide to implement a custom TitleBar in QMainWindow, for manually handle the events of close,minimize and move. This way allow me to receive the onMousePress, onMouseRelease and onMouseMove on the titleBar, and so i can modify the position of the second form in every moment.

    But when i press the minimize button on QMainWindow, the window is hiding and it's shown in the tray: if i click in the icon on tray, the window doesn't go on top. What is the signal that i have to connect to do this?
    I try to reimplement showEvent of QMainWindow with no positive result.
    Thanks a lot for all answers

    EDIT: i use this tutorial to implement the custom title bar: "guide":http://qt-project.org/faq/answer/how_can_i_handle_events_in_the_titlebar_and_change_its_color_etc

    EDIT 2: i found the mistake: i had connect the SIGNAL clicked() of the button for minimization with the hide() SLOT instead showMinimized().


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.