Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWidget:: close button hint
QtWS25 Last Chance

QWidget:: close button hint

Scheduled Pinned Locked Moved General and Desktop
11 Posts 6 Posters 11.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    haney
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • V Offline
      V Offline
      veeeee_d
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        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!

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • H Offline
          H Offline
          haney
          wrote on last edited by
          #4

          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..

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            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.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • H Offline
              H Offline
              haney
              wrote on last edited by
              #6

              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..

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                [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 :-)

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  haney
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #9

                    [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.

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      Poonam15
                      wrote on last edited by
                      #10

                      Hi Haney,

                      You can use "close()" function simply by putting a push button and writing clicked slot for this button

                      JonBJ 1 Reply Last reply
                      0
                      • P Poonam15

                        Hi Haney,

                        You can use "close()" function simply by putting a push button and writing clicked slot for this button

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #11

                        @Poonam15
                        You can, but this was not the OP's question from 2011, he wanted a window to have a close button on its title bar.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved