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. How to create VS2013 like frameless window with dark style
Forum Updated to NodeBB v4.3 + New Features

How to create VS2013 like frameless window with dark style

Scheduled Pinned Locked Moved Unsolved General and Desktop
45 Posts 5 Posters 18.0k Views 5 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.
  • Chris KawaC Offline
    Chris KawaC Offline
    Chris Kawa
    Lifetime Qt Champion
    wrote on last edited by
    #7

    @mrjj One technique for drawing tabs and whatnot on the titlebar is combination of what I described and what's in that article I linked to - extending the client area onto the frame to allow custom painting, but leaving couple pixels to let Windows handle the resizing etc. This comes with its own set of problems though ;)

    mrjjM 1 Reply Last reply
    1
    • Chris KawaC Chris Kawa

      @mrjj One technique for drawing tabs and whatnot on the titlebar is combination of what I described and what's in that article I linked to - extending the client area onto the frame to allow custom painting, but leaving couple pixels to let Windows handle the resizing etc. This comes with its own set of problems though ;)

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #8

      @Chris-Kawa
      I also wonder if all the link says still applies in windows 10.
      The glass effect api its still present but have no effect.
      Some of it seems in Qt already
      http://doc.qt.io/qt-5/qtwin.html#extendFrameIntoClientArea

      So its fair to say its huge work to get a perfectly working version :)

      1 Reply Last reply
      0
      • Chris KawaC Chris Kawa

        Hi, thanks for sharing.

        I don't know if you welcome feedback, but here are couple of issues that always come up with this particular technique and don't get handled correctly:

        • I can move maximized window by dragging the title bar and it doesn't "demaximize". It should return to the "normal" size.
        • The window can't be resized using borders. This ranges from major annoyance to a real usability issue - when I maximized the window and then moved it by dragging title bar the window still has the size of the whole screen, which means the resize area on the status bar went under the taskbar. Without ability to resize using borders I'm stuck or I have to precisely move the window back close to the top screen border to see the status bar again.
        • The window lost the system shadow. Small issue, but important for subconscious depth perception. Starting with Windows 8 it also serves as a resize area. The window frame is 1px wide so the shadow serves as a border so you don't have to be that precise.
        • The window frame doesn't differentiate between active and inactive state (I don't mean disabled, I mean when another window is active). It's a big usability issue.
        • Windows applications should reserve the upper left corner for system menu. Usually there's an app icon there, but even when there's not (e.g. Google Chrome) that area should show system menu when clicked and close the app when double clicked. It's a platform guidelines breaking issue.
        • Because of the frameless window hint Aero features stopped working:
          • Aero snap - dragging a window to screen's border should trigger Aero snap.
          • Pressing Win+arrows should move between borders of the screen and/or maximize/demaximize
        • Window ignores system-wide OS shortcuts, for example Win+M, which minimizes all windows.
        • Just to make it easier to use I'd separate the "solution" files from the "example" files into separate directories. Right now one needs to read all the code to know what can be removed and what needs to stay. The solution should be "plug and play" i.e. drop in your project , include or inherit and that's it. Now I'd need to modify your files to use it in my code.
        J Offline
        J Offline
        Jorgen
        wrote on last edited by
        #9

        @Chris-Kawa Wow, thx for the deep review and comments. As I said before it is the first initial example, of a simple way to style and decorate dialogs. To get all the features to have native feeling - I had to add OS specific code inside.
        So I think I will create a dev branch to make a more windows native version with some points from your list.

        The reason I started this was the dark style I created times ago based on fusion and applied stylesheets. It looks great on Systems with dark window styles - but on Windows7 it looks terrible. I have to use Windows for my day job, so I'm, using there VS2013/2015/2017... and I really like the style/theme and the frameless window.

        So I started to make this little example to "look" like the Visual Studio IDE ;)

        Maybe someone else is interested in improving my code by @Chris-Kawa s List. You are welcome to do it

        mrjjM AsimovA 2 Replies Last reply
        2
        • J Jorgen

          @Chris-Kawa Wow, thx for the deep review and comments. As I said before it is the first initial example, of a simple way to style and decorate dialogs. To get all the features to have native feeling - I had to add OS specific code inside.
          So I think I will create a dev branch to make a more windows native version with some points from your list.

          The reason I started this was the dark style I created times ago based on fusion and applied stylesheets. It looks great on Systems with dark window styles - but on Windows7 it looks terrible. I have to use Windows for my day job, so I'm, using there VS2013/2015/2017... and I really like the style/theme and the frameless window.

          So I started to make this little example to "look" like the Visual Studio IDE ;)

          Maybe someone else is interested in improving my code by @Chris-Kawa s List. You are welcome to do it

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #10

          @Jorgen
          You are not alone liking dark and frame less so many people would be happy
          for a good solution to download. Even if its windows only.

          1 Reply Last reply
          0
          • J Jorgen

            @Chris-Kawa Wow, thx for the deep review and comments. As I said before it is the first initial example, of a simple way to style and decorate dialogs. To get all the features to have native feeling - I had to add OS specific code inside.
            So I think I will create a dev branch to make a more windows native version with some points from your list.

            The reason I started this was the dark style I created times ago based on fusion and applied stylesheets. It looks great on Systems with dark window styles - but on Windows7 it looks terrible. I have to use Windows for my day job, so I'm, using there VS2013/2015/2017... and I really like the style/theme and the frameless window.

            So I started to make this little example to "look" like the Visual Studio IDE ;)

            Maybe someone else is interested in improving my code by @Chris-Kawa s List. You are welcome to do it

            AsimovA Offline
            AsimovA Offline
            Asimov
            wrote on last edited by
            #11

            @Jorgen
            I would love to see a youtube video showing how you go about styling a dialog.
            I wonder if you would be up for that.

            I mean start with an empty qt and show how you go about doing some simple styling, because I have no idea how it works, even though I have looked at your code.

            J 1 Reply Last reply
            0
            • AsimovA Asimov

              @Jorgen
              I would love to see a youtube video showing how you go about styling a dialog.
              I wonder if you would be up for that.

              I mean start with an empty qt and show how you go about doing some simple styling, because I have no idea how it works, even though I have looked at your code.

              J Offline
              J Offline
              Jorgen
              wrote on last edited by
              #12

              @Asimov good idea - I'm really busy - but I try to make such a tutorial video next few weeks.
              I currently using some "tricks" to do this. The important one, is to embed my "main" window into another one, which has some window flags to make it frameless. (like a splash screen).
              After that I can add my buttons (minimize, maximize, close, ...) the title bar etc. to my upper window layout. And of course using stylesheets to give the outer window a nice look and feel.

              All the "magic" with drag & drop on titlebar or minimize/maximize is also done in the outer window by overloading mouse events.

              ToDOs:

              • maybe install eventFilter or connect signals from embed window, to get all the changes (if you change the size, make it maximize, etc...)
              • also implement resize by all borders, not only the sizeGrid
              • and improve all the stuff @Chris-Kawa mentioned before
              1 Reply Last reply
              1
              • J Offline
                J Offline
                Jorgen
                wrote on last edited by
                #13

                Guys I had some spare time to update my Repo: https://github.com/Jorgen-VikingGod/Qt-Frameless-Window-DarkStyle

                There is now a much more improved frameless window, separated into extra classes to make it easier to use in existing projects. Also add feature to handle active/inactive or focus/no focus.

                I also added a kind of drop shadow around the window. If it is active the shadow/glow is blue (=highlight color from palette) else it is dark.

                There is also now a ui file for the frameless window, so you can easy move the buttons, change the layout, style, etc...

                Here is simple example of using the frameless window:

                #include <QApplication>
                #include "DarkStyle.h"
                #include "framelesswindow.h"
                #include "mainwindow.h"
                
                int main(int argc, char *argv[])
                {
                  QApplication a(argc, argv);
                
                  // style our application with custom dark style
                  CDarkStyle::assign();
                
                  // create frameless window (and set windowState or title)
                  FramelessWindow framelessWindow;
                  //framelessWindow.setWindowState(Qt::WindowMaximized);
                  //framelessWindow.setWindowTitle("test title");
                
                  // create our mainwindow
                  MainWindow mainWindow;
                
                  // add the mainwindow to our custom frameless window
                  framelessWindow.setContent(&mainWindow);
                  framelessWindow.show();
                
                  return a.exec();
                }
                
                1 Reply Last reply
                1
                • Chris KawaC Offline
                  Chris KawaC Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by
                  #14

                  @Jorgen Note that FramelessWindow takes ownership of the content so the example is "order dependent" i.e. this

                  FramelessWindow framelessWindow;
                  MainWindow mainWindow;
                  framelessWindow.setContent(&mainWindow);
                  

                  will work, but this

                  MainWindow mainWindow;
                  FramelessWindow framelessWindow;
                  framelessWindow.setContent(&mainWindow);
                  

                  will crash at exit. A more Qtish way of doing it would be

                  FramelessWindow framelessWindow;
                  MainWindow* mainWindow = new MainWindow;
                  framelessWindow.setContent(mainWindow);
                  

                  to let the parent/child mechanism clean up.
                  This way order of creation doesn't matter and it might be less error prone example.

                  J 1 Reply Last reply
                  1
                  • Chris KawaC Chris Kawa

                    @Jorgen Note that FramelessWindow takes ownership of the content so the example is "order dependent" i.e. this

                    FramelessWindow framelessWindow;
                    MainWindow mainWindow;
                    framelessWindow.setContent(&mainWindow);
                    

                    will work, but this

                    MainWindow mainWindow;
                    FramelessWindow framelessWindow;
                    framelessWindow.setContent(&mainWindow);
                    

                    will crash at exit. A more Qtish way of doing it would be

                    FramelessWindow framelessWindow;
                    MainWindow* mainWindow = new MainWindow;
                    framelessWindow.setContent(mainWindow);
                    

                    to let the parent/child mechanism clean up.
                    This way order of creation doesn't matter and it might be less error prone example.

                    J Offline
                    J Offline
                    Jorgen
                    wrote on last edited by
                    #15

                    @Chris-Kawa thanks again for great tips.
                    Repo is now up to date.

                    1 Reply Last reply
                    1
                    • S Offline
                      S Offline
                      saeid0034
                      wrote on last edited by
                      #16

                      hi im new to qt and c++, i wand to use this this Qt-Frameless-Window-DarkStyle on multi ui file
                      but i dont know how
                      every time i try all my ui file showed in a window together...
                      anyone can help me

                      mrjjM 1 Reply Last reply
                      0
                      • S saeid0034

                        hi im new to qt and c++, i wand to use this this Qt-Frameless-Window-DarkStyle on multi ui file
                        but i dont know how
                        every time i try all my ui file showed in a window together...
                        anyone can help me

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #17

                        Hi and welcome to the forums

                        Did you try to create a frameless for each ?

                        // 1
                        FramelessWindow * framelessWindow = new FramelessWindow;
                        MainWindow *mainWindow = new MainWindow;
                        framelessWindow->setContent(mainWindow);
                        // 2
                        FramelessWindow * framelessWindow2 = new FramelessWindow;
                        MainWindow *mainWindow2 = new MainWindow;
                        framelessWindow2->setContent(mainWindow2);

                        S 1 Reply Last reply
                        1
                        • mrjjM mrjj

                          Hi and welcome to the forums

                          Did you try to create a frameless for each ?

                          // 1
                          FramelessWindow * framelessWindow = new FramelessWindow;
                          MainWindow *mainWindow = new MainWindow;
                          framelessWindow->setContent(mainWindow);
                          // 2
                          FramelessWindow * framelessWindow2 = new FramelessWindow;
                          MainWindow *mainWindow2 = new MainWindow;
                          framelessWindow2->setContent(mainWindow2);

                          S Offline
                          S Offline
                          saeid0034
                          wrote on last edited by saeid0034
                          #18

                          @mrjj said in How to create VS2013 like frameless window with dark style:

                          // 1
                          FramelessWindow * framelessWindow = new FramelessWindow;
                          MainWindow *mainWindow = new MainWindow;
                          framelessWindow->setContent(mainWindow);
                          // 2
                          FramelessWindow * framelessWindow2 = new FramelessWindow;
                          MainWindow *mainWindow2 = new MainWindow;
                          framelessWindow2->setContent(mainWindow2);

                          thanks for fast reply
                          this code doesn't work
                          this time no ui come up at all

                          my code first of all open a window
                          when i click a button in first windows, second window open (first window hide)

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            saeid0034
                            wrote on last edited by
                            #19
                            a.setStyle(new DarkStyle);
                            
                              // create frameless window (and set windowState or title)
                              FramelessWindow framelessWindow;
                              //framelessWindow.setWindowState(Qt::WindowMaximized);
                              framelessWindow.setWindowTitle("SubRan Patcher");
                              framelessWindow.setWindowIcon(QIcon(":/png/sr-removebg-preview.png"));
                            
                              // create our mainwindow instance
                              MainWindow *mainwindow = new MainWindow;
                              MainWindow2 *mainwindow2 = new MainWindow2;
                            
                              // add the mainwindow to our custom frameless window
                              framelessWindow.setContent(mainwindow);
                              framelessWindow.setContent(mainwindow2);
                              framelessWindow.show();
                            
                              return a.exec();
                            

                            when i use this code my program start like this
                            1d86c029-0a04-4c18-8e3c-a15df0f36f60-image.png

                            as you can see my two windows showed together in one window

                            1 Reply Last reply
                            0
                            • mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by mrjj
                              #20

                              Hi
                              You still using same frameless for both
                              framelessWindow.setContent(mainwindow);
                              framelessWindow.setContent(mainwindow2);

                              S 1 Reply Last reply
                              2
                              • mrjjM mrjj

                                Hi
                                You still using same frameless for both
                                framelessWindow.setContent(mainwindow);
                                framelessWindow.setContent(mainwindow2);

                                S Offline
                                S Offline
                                saeid0034
                                wrote on last edited by saeid0034
                                #21

                                @mrjj said in How to create VS2013 like frameless window with dark style:

                                Hi
                                You still using same frameless for both
                                framelessWindow.setContent(mainwindow);
                                framelessWindow.setContent(mainwindow2);

                                what can i do about this?
                                i use 2 frameless in my test too but the output is second window doesn't show (only a empty frameless window show)

                                also i use this code in mainwindow.cpp to show new window and hide old one

                                void MainWindow::on_pushButton_clicked()
                                {
                                    // ----- Hide old Window and show new window ----- //
                                     hide();
                                     mainwindow2 = new MainWindow2(this);
                                }
                                
                                mrjjM 1 Reply Last reply
                                0
                                • S saeid0034

                                  @mrjj said in How to create VS2013 like frameless window with dark style:

                                  Hi
                                  You still using same frameless for both
                                  framelessWindow.setContent(mainwindow);
                                  framelessWindow.setContent(mainwindow2);

                                  what can i do about this?
                                  i use 2 frameless in my test too but the output is second window doesn't show (only a empty frameless window show)

                                  also i use this code in mainwindow.cpp to show new window and hide old one

                                  void MainWindow::on_pushButton_clicked()
                                  {
                                      // ----- Hide old Window and show new window ----- //
                                       hide();
                                       mainwindow2 = new MainWindow2(this);
                                  }
                                  
                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by mrjj
                                  #22

                                  @saeid0034
                                  so you did try with
                                  FramelessWindow framelessWindow;
                                  FramelessWindow framelessWindow2;

                                  and it wont show ?

                                  also the on_pushButton_clicked will just make a new one and NOT USE frameless as you dont add that ot it like you do in main.

                                  S 1 Reply Last reply
                                  1
                                  • mrjjM mrjj

                                    @saeid0034
                                    so you did try with
                                    FramelessWindow framelessWindow;
                                    FramelessWindow framelessWindow2;

                                    and it wont show ?

                                    also the on_pushButton_clicked will just make a new one and NOT USE frameless as you dont add that ot it like you do in main.

                                    S Offline
                                    S Offline
                                    saeid0034
                                    wrote on last edited by saeid0034
                                    #23

                                    @mrjj said in How to create VS2013 like frameless window with dark style:

                                    @saeid0034
                                    so you did try with
                                    FramelessWindow framelessWindow;
                                    FramelessWindow framelessWindow2;

                                    and it wont show ?

                                    also the on_pushButton_clicked will just make a new one and NOT USE frameless as you dont add that ot it like you do in main.

                                    what can i do?
                                    you mean i need somthing like this in my mainwindow.cpp?

                                    void MainWindow::on_pushButton_clicked()
                                    {
                                        // ----- Hide old Window and show new window ----- //
                                         hide();
                                    
                                         // style our application with custom dark style
                                         setStyle(new DarkStyle);
                                    
                                         // create frameless window (and set windowState or title)
                                         FramelessWindow framelessWindow2;
                                         //framelessWindow.setWindowState(Qt::WindowMaximized);
                                         framelessWindow2.setWindowTitle(".r");
                                         framelessWindow2.setWindowIcon(QIcon(":/png/sr-removebg-preview.png"));
                                    
                                         // create our mainwindow instance
                                         MainWindow2 *mainwindow2 = new MainWindow2;
                                    
                                         // add the mainwindow to our custom frameless window
                                         framelessWindow2.setContent(mainwindow2);
                                         framelessWindow2.show();
                                    
                                         //mainwindow2 = new MainWindow2(this);
                                    }
                                    

                                    sorry for asking lots of question (and sorry about mistake in framelessWindow2.setWindowTitle in above code)

                                    mrjjM S 2 Replies Last reply
                                    0
                                    • S saeid0034

                                      @mrjj said in How to create VS2013 like frameless window with dark style:

                                      @saeid0034
                                      so you did try with
                                      FramelessWindow framelessWindow;
                                      FramelessWindow framelessWindow2;

                                      and it wont show ?

                                      also the on_pushButton_clicked will just make a new one and NOT USE frameless as you dont add that ot it like you do in main.

                                      what can i do?
                                      you mean i need somthing like this in my mainwindow.cpp?

                                      void MainWindow::on_pushButton_clicked()
                                      {
                                          // ----- Hide old Window and show new window ----- //
                                           hide();
                                      
                                           // style our application with custom dark style
                                           setStyle(new DarkStyle);
                                      
                                           // create frameless window (and set windowState or title)
                                           FramelessWindow framelessWindow2;
                                           //framelessWindow.setWindowState(Qt::WindowMaximized);
                                           framelessWindow2.setWindowTitle(".r");
                                           framelessWindow2.setWindowIcon(QIcon(":/png/sr-removebg-preview.png"));
                                      
                                           // create our mainwindow instance
                                           MainWindow2 *mainwindow2 = new MainWindow2;
                                      
                                           // add the mainwindow to our custom frameless window
                                           framelessWindow2.setContent(mainwindow2);
                                           framelessWindow2.show();
                                      
                                           //mainwindow2 = new MainWindow2(this);
                                      }
                                      

                                      sorry for asking lots of question (and sorry about mistake in framelessWindow2.setWindowTitle in above code)

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #24

                                      Hi
                                      seems ok.
                                      Yes you need to to the same each time you create a Window you want to be frame less

                                      one thing.

                                      setStyle(new DarkStyle);

                                      that sets on the current MainWindow and i thnik you need that on the new one

                                      // create our mainwindow instance
                                      MainWindow2 *mainwindow2 = new MainWindow2;
                                      mainwindow2 -> setStyle(new DarkStyle);

                                      • sorry for asking lots of question
                                        That is quite allright :)
                                      S 1 Reply Last reply
                                      1
                                      • S saeid0034

                                        @mrjj said in How to create VS2013 like frameless window with dark style:

                                        @saeid0034
                                        so you did try with
                                        FramelessWindow framelessWindow;
                                        FramelessWindow framelessWindow2;

                                        and it wont show ?

                                        also the on_pushButton_clicked will just make a new one and NOT USE frameless as you dont add that ot it like you do in main.

                                        what can i do?
                                        you mean i need somthing like this in my mainwindow.cpp?

                                        void MainWindow::on_pushButton_clicked()
                                        {
                                            // ----- Hide old Window and show new window ----- //
                                             hide();
                                        
                                             // style our application with custom dark style
                                             setStyle(new DarkStyle);
                                        
                                             // create frameless window (and set windowState or title)
                                             FramelessWindow framelessWindow2;
                                             //framelessWindow.setWindowState(Qt::WindowMaximized);
                                             framelessWindow2.setWindowTitle(".r");
                                             framelessWindow2.setWindowIcon(QIcon(":/png/sr-removebg-preview.png"));
                                        
                                             // create our mainwindow instance
                                             MainWindow2 *mainwindow2 = new MainWindow2;
                                        
                                             // add the mainwindow to our custom frameless window
                                             framelessWindow2.setContent(mainwindow2);
                                             framelessWindow2.show();
                                        
                                             //mainwindow2 = new MainWindow2(this);
                                        }
                                        

                                        sorry for asking lots of question (and sorry about mistake in framelessWindow2.setWindowTitle in above code)

                                        S Offline
                                        S Offline
                                        saeid0034
                                        wrote on last edited by
                                        #25
                                        This post is deleted!
                                        1 Reply Last reply
                                        0
                                        • mrjjM mrjj

                                          Hi
                                          seems ok.
                                          Yes you need to to the same each time you create a Window you want to be frame less

                                          one thing.

                                          setStyle(new DarkStyle);

                                          that sets on the current MainWindow and i thnik you need that on the new one

                                          // create our mainwindow instance
                                          MainWindow2 *mainwindow2 = new MainWindow2;
                                          mainwindow2 -> setStyle(new DarkStyle);

                                          • sorry for asking lots of question
                                            That is quite allright :)
                                          S Offline
                                          S Offline
                                          saeid0034
                                          wrote on last edited by saeid0034
                                          #26

                                          @mrjj said in How to create VS2013 like frameless window with dark style:

                                          Hi
                                          seems ok.
                                          Yes you need to to the same each time you create a Window you want to be frame less

                                          one thing.

                                          setStyle(new DarkStyle);

                                          that sets on the current MainWindow and i thnik you need that on the new one

                                          // create our mainwindow instance
                                          MainWindow2 *mainwindow2 = new MainWindow2;
                                          mainwindow2 -> setStyle(new DarkStyle);

                                          • sorry for asking lots of question
                                            That is quite allright :)

                                          i tested it with following code

                                                   hide();
                                                   // create frameless window (and set windowState or title)
                                                   FramelessWindow framelessWindow2;
                                                   //framelessWindow.setWindowState(Qt::WindowMaximized);
                                                   framelessWindow2.setWindowTitle(".r");
                                                   framelessWindow2.setWindowIcon(QIcon(":/png/sr-removebg-preview.png"));
                                          
                                                   // create our mainwindow instance
                                                   MainWindow2 *mainwindow2 = new MainWindow2;
                                                   mainwindow2 -> setStyle(new DarkStyle);
                                          
                                                   // add the mainwindow to our custom frameless window
                                                   framelessWindow2.setContent(mainwindow2);
                                                   framelessWindow2.show();
                                          
                                                   //mainwindow2 = new MainWindow2(this);
                                          

                                          but again it show me only a blank frameless window of my second ui file

                                          bdc7674c-a57e-441e-869c-56bbf4dd7ac8-image.png

                                          one other point is as you can see WindowTitle is test (i use this title in my frist windown in main.cpp) its not use new WindowTitle i set in above code

                                          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