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. Is there any ways to change the outstyle of the window close button?
Qt 6.11 is out! See what's new in the release blog

Is there any ways to change the outstyle of the window close button?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 959 Views 2 Watching
  • 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.
  • nicker playerN Offline
    nicker playerN Offline
    nicker player
    wrote on last edited by
    #1

    I found that some projects set the Window flag so that we can define a single button to replace the default window close button.So is there any other easilier ways to change the outstyle of the close button?

    Pl45m4P 1 Reply Last reply
    0
    • nicker playerN nicker player

      I found that some projects set the Window flag so that we can define a single button to replace the default window close button.So is there any other easilier ways to change the outstyle of the close button?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @nicker-player

      Create a window without the default window decoration (e.g. Qt::FramelessWindowHint) and then make your own buttons to close, maxi- or minimize your window.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      nicker playerN 1 Reply Last reply
      0
      • Pl45m4P Pl45m4

        @nicker-player

        Create a window without the default window decoration (e.g. Qt::FramelessWindowHint) and then make your own buttons to close, maxi- or minimize your window.

        nicker playerN Offline
        nicker playerN Offline
        nicker player
        wrote on last edited by
        #3

        @Pl45m4 said in Is there any ways to change the outstyle of the window close button?:

        Qt::FramelessWindowHint

        I set the Qt::FramelessWindowHint attribute on the widget of the dockview,but it seemed useless.When the dockview object docked on the main window,the close button is still there ,and when it is floating out of the main window,the close button doesnt disappeared too.

        Pl45m4P 1 Reply Last reply
        0
        • nicker playerN nicker player

          @Pl45m4 said in Is there any ways to change the outstyle of the window close button?:

          Qt::FramelessWindowHint

          I set the Qt::FramelessWindowHint attribute on the widget of the dockview,but it seemed useless.When the dockview object docked on the main window,the close button is still there ,and when it is floating out of the main window,the close button doesnt disappeared too.

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          @nicker-player

          You could have mentioned, that we are dealing with a QDockWidget here.

          But almost the same answer:
          Make your own title bar widget with your buttons and use

          • https://doc.qt.io/qt-6/qdockwidget.html#setTitleBarWidget

          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          nicker playerN 1 Reply Last reply
          0
          • Pl45m4P Pl45m4

            @nicker-player

            You could have mentioned, that we are dealing with a QDockWidget here.

            But almost the same answer:
            Make your own title bar widget with your buttons and use

            • https://doc.qt.io/qt-6/qdockwidget.html#setTitleBarWidget
            nicker playerN Offline
            nicker playerN Offline
            nicker player
            wrote on last edited by
            #5

            @Pl45m4

               if(mode=="Default"||mode.isEmpty()){
                    // 
                    qDebug()<<"int UiPaneDockViewdetail::setTitleBarMode()-Default";
                    QWidget* t_TitleBar = this->titleBarWidget();
                    QWidget* t_DefaultWidget = new QWidget();
                    this->setTitleBarWidget(t_DefaultWidget);
                    delete t_TitleBar;
                    //t_TitleBar->hide();
                }
                else if(mode=="Alone"){
                    qDebug()<<"int UiPaneDockViewdetail::setTitleBarMode()-Alone";
                    QWidget* t_TitleBar = this->titleBarWidget();
                    QWidget* t_DefaultWidget = new QWidget();
                    setWindowFlags(Qt::WindowMinimizeButtonHint
                                                    | Qt::WindowMaximizeButtonHint
                                                    | Qt::CustomizeWindowHint);
                    setTitleBarWidget(t_DefaultWidget);
                    delete t_TitleBar;
                }
            

            I just want to switch the mode of the window between close button style and the no closed button style.You see the ALONE mode dosent work.I dont know why.Cause I dont know the way.

            JonBJ 1 Reply Last reply
            0
            • nicker playerN nicker player

              @Pl45m4

                 if(mode=="Default"||mode.isEmpty()){
                      // 
                      qDebug()<<"int UiPaneDockViewdetail::setTitleBarMode()-Default";
                      QWidget* t_TitleBar = this->titleBarWidget();
                      QWidget* t_DefaultWidget = new QWidget();
                      this->setTitleBarWidget(t_DefaultWidget);
                      delete t_TitleBar;
                      //t_TitleBar->hide();
                  }
                  else if(mode=="Alone"){
                      qDebug()<<"int UiPaneDockViewdetail::setTitleBarMode()-Alone";
                      QWidget* t_TitleBar = this->titleBarWidget();
                      QWidget* t_DefaultWidget = new QWidget();
                      setWindowFlags(Qt::WindowMinimizeButtonHint
                                                      | Qt::WindowMaximizeButtonHint
                                                      | Qt::CustomizeWindowHint);
                      setTitleBarWidget(t_DefaultWidget);
                      delete t_TitleBar;
                  }
              

              I just want to switch the mode of the window between close button style and the no closed button style.You see the ALONE mode dosent work.I dont know why.Cause I dont know the way.

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

              @nicker-player
              I am jumping into this conversation, and know nothing about QDockWidget :)

              There are a few hits if you Google for settitlebarwidget which you might want to read through. there are obviously some "funnies" about dock titlebar widgets and different platforms.

              Please always tell us which platform you are on for questions like this.

              Among these https://stackoverflow.com/q/28502134/489865 claims

              Setting custom title bar widget changes the windows flags on Windows

              See whether moving your setWindowFlags() to after the setTitleBarWidget() makes any difference? But your issue may be different from this.

              1 Reply Last reply
              0
              • Pl45m4P Offline
                Pl45m4P Offline
                Pl45m4
                wrote on last edited by
                #7

                @nicker-player said in Is there any ways to change the outstyle of the window close button?:

                    setWindowFlags(Qt::WindowMinimizeButtonHint
                                                    | Qt::WindowMaximizeButtonHint
                                                    | Qt::CustomizeWindowHint);
                

                I think these flags have no effect when using the title bar widget.
                Try one from here:

                • https://doc.qt.io/qt-6/qdockwidget.html#DockWidgetFeature-enum

                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                nicker playerN 1 Reply Last reply
                0
                • Pl45m4P Pl45m4

                  @nicker-player said in Is there any ways to change the outstyle of the window close button?:

                      setWindowFlags(Qt::WindowMinimizeButtonHint
                                                      | Qt::WindowMaximizeButtonHint
                                                      | Qt::CustomizeWindowHint);
                  

                  I think these flags have no effect when using the title bar widget.
                  Try one from here:

                  • https://doc.qt.io/qt-6/qdockwidget.html#DockWidgetFeature-enum
                  nicker playerN Offline
                  nicker playerN Offline
                  nicker player
                  wrote on last edited by
                  #8

                  @Pl45m4
                  I found that the dockwidet only could be added by the qmainwindow object.But in fact I used the qwidget to add the dockwidget.Are there any problems to use like this?
                  And the way you just mentioned setFeatures dosent work.I dont know why.

                   QWidget* t_TitleBar = this->titleBarWidget();
                          QWidget* t_DefaultWidget =  new QWidget(this);
                          setTitleBarWidget(t_DefaultWidget);
                          setFeatures(QDockWidget::DockWidgetMovable
                                      |QDockWidget::DockWidgetFloatable
                                      |QDockWidget::DockWidgetClosable);
                          delete t_TitleBar;
                  
                  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