QWidget:: close button hint



  • Hi,
    I have a MainWidget which has Widget1 and Widget2 added in a QVBoxLayout. Widget1 is inherited from QTextEdit. Widget2 is inherited from QWidget.

    Now I need to have a closeButton hint for Widget2 and that Widget2 must be closable. In Widget2 ctor I tried
    @
    setWindowFlags(Qt::CustomizeWindowHint);
    setWindowFlags(Qt::WindowCloseButtonHint);
    @
    But this did not work.

    Plz suggest how do I have close button for my widget2.

    Thanks



  • "This":http://doc.qt.nokia.com/4.7/widgets-windowflags.html example teaches you to use the window flags.



  • setWindowFlags sets all flags at once. You must do a bitwise or of all flags:

    @
    setWindowFlags(Qt::CustomizeWindowHint) | Qt::WindowCloseButtonHint);
    @

    Be aware that with that line, you reset every other flag!



  • I tried @setWindowFlags(Qt::CustomizeWindowHint) | Qt::WindowCloseButtonHint);@ But it is not working in my case.

    In my mainwidget, I am adding Widget1 and Widget2 in a QVBoxLayout. Can a widget2 in a QVBoxLayout have a Close button hint as I needed.

    I need to have a closebutton for my Widget2, after adding it to a VBoxLayout. I am working on openSuSe 12.1 OS.

    Thanks..



  • The close buttons (and the other elements settable by window flags) are for toplevel windows only. Most if not all of them do not have any influence on child widgets.

    So, the short story: no, you can't have a close button on a subwidget by setting a window flag.



  • Ok thanks for the info..

    I wrote a keypressevent for widget2 and catching Key_Escape and then hiding the widget.. Just a workaround..

    <CLOSED>

    Thanks..



  • [quote author="haney" date="1323344057"]Ok thanks for the info..
    <CLOSED>
    [/quote]
    Closing of topics is only done when needed, and then by moderators or admins. So, topic is not closed. I am, however, glad it is [Solved] for you :-)



  • Hi all,

    I need to have at least a small icon/button/action in my widget to have CLOSE button functionality. There should be some obvious symbol/icon for the user to understand that there is CLOSE option for my widget.

    Appreciate your help in this regard.

    Thanks,
    Haney.



  • [quote author="haney" date="1337167277"]Hi all,

    I need to have at least a small icon/button/action in my widget to have CLOSE button functionality. There should be some obvious symbol/icon for the user to understand that there is CLOSE option for my widget.

    Appreciate your help in this regard.

    Thanks,
    Haney.[/quote]

    As you could have read in this topic already: there is no* support for providing close buttons/hints/options/whatevers for non-top-level widgets in Qt. If you want to provide that functionality, you will have to provide it.

    *) Ok, perhaps there is some, like the close buttons on tabs, but not for the general case.


Log in to reply
 

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