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. Create Custom Window, with custom TitleBar
QtWS25 Last Chance

Create Custom Window, with custom TitleBar

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 1.4k 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.
  • A Offline
    A Offline
    Andrea_Venturelli
    wrote on 1 Oct 2024, 10:57 last edited by
    #3

    sorry, I only include the directory where all the .cpp, .h and .ui is located.. what I need to do to my ".pro" file ?
    image.png

    J 1 Reply Last reply 1 Oct 2024, 10:59
    0
    • A Andrea_Venturelli
      1 Oct 2024, 10:57

      sorry, I only include the directory where all the .cpp, .h and .ui is located.. what I need to do to my ".pro" file ?
      image.png

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 1 Oct 2024, 10:59 last edited by
      #4

      @Andrea_Venturelli Again: you need WindowFrame.cpp. You have to add it to SOURCES.
      And please post error messages and code as text not pictures.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • A Andrea_Venturelli
        1 Oct 2024, 10:51

        Hi guys, I'm struggling a lot in creating a FramelessWindow which can be attached with a custom Titlebar (that is a custom widget derived from QWidget).

        be1b4a49-ec0a-4003-a3fd-9974d4de24c0-image.png

        the top red-rectangle is my custom Titlebar Widget (called in the project as "WindowFrame") which has a cunstructor that accept 2 QString for setting the parameter to the Profile_banner and the QWidget* parent parameter as illustrated here:
        7d1b4cc9-cfc6-4bf0-b52f-bee894c08c71-image.png .

        this is a stand alone Qt project with is own ".pro" file.
        I have another project directory where I have this UI:
        3a5cd9cf-00e4-4679-b4ea-551a2907e710-image.png
        0158cc75-31e2-46ed-bdda-d693a7398297-image.png

        My Plan was:

        • INCLUDEPATH += "the path to my CustomTitleBar" to my TrackManager.pro file
        • Create an instance of WindowFrame as a member
        • In the constructor for TrackManager, retrive the verticalBoxLayout and add it at the top.
          b926bb4b-b6f6-44e2-a970-c49d90774e34-image.png

        but when I run the program, give me an error saing: 6add13d9-5d60-44e1-8292-abd90bb16d8d-image.png

        My question is: What is the smartest and optimal approch to create a custom Window with Interchangable TitleBar ?

        I use C++17 , Qt Creator Latest version, and MinGW64 for building.

        P Offline
        P Offline
        Pl45m4
        wrote on 1 Oct 2024, 11:37 last edited by Pl45m4 10 Jan 2024, 11:44
        #5

        @Andrea_Venturelli

        Hi,

        if you have multiple and different "title bar" widgets, which you want to show depending on your configuration or user, looking at the Document Viewer example may help.
        This project uses different viewer widgets (loaded as Qt plugin library) for each context of the app

        • https://doc.qt.io/qt-6/qtdoc-demos-documentviewer-example.html

        Try this, when you have multiple title bar widgets, or you simply include the one class in your app like @jsulm said.


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

        ~E. W. Dijkstra

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Andrea_Venturelli
          wrote on 1 Oct 2024, 12:37 last edited by Andrea_Venturelli 10 Jan 2024, 12:44
          #6

          guys I added the .cpp file to the "SOURCE" param of the ".pro" file and now the error message has changed to the following:

          C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: debug/windowframe.o: in function `WindowFrame::on_maximize_tbnt_clicked()':
          C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: debug/windowframe.o: in function `WindowFrame::on_minimize_tbtn_clicked()':
          collect2.exe: error: ld returned 1 exit status
          C:\Users\path\Qt_c++\TrackInspector\windowframe.cpp:50: error: undefined reference to `WindowFrame::showNormalClicked()'
          :-1: error: C:\Users\path\Qt_c++\TrackInspector\build\Desktop_Qt_6_7_1_MinGW_64_bit-Debug/../../windowframe.cpp:54: undefined reference to `WindowFrame::maximizedClicked()'
          C:\Users\path\Qt_c++\TrackInspector\windowframe.cpp:61: error: undefined reference to `WindowFrame::minimizedClicked()'
          :-1: error: debug/windowframe.o:windowframe.cp:(.rdata$.refptr._ZTV11WindowFrame[.refptr._ZTV11WindowFrame]+0x0): undefined reference to `vtable for WindowFrame'
          :-1: error: [Makefile.Debug:83: debug/TrackInspector.exe] Error 1
          

          My .pro file look like this now:

          QT       += core gui
          
          greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
          
          CONFIG += c++17
          
          # You can make your code fail to compile if it uses deprecated APIs.
          # In order to do so, uncomment the following line.
          #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
          
          SOURCES += \
              main.cpp \
              trackmanager.cpp \
              windowframe.cpp
          
          HEADERS += \
              ../TitleCustomBar/profilebanner.h \
              trackmanager.h
              windowframe.h
          
          FORMS += \
              ../TitleCustomBar/profilebanner.ui \
              ../TitleCustomBar/windowframe.ui \
              trackmanager.ui
          
          # Default rules for deployment.
          qnx: target.path = /tmp/$${TARGET}/bin
          else: unix:!android: target.path = /opt/$${TARGET}/bin
          !isEmpty(target.path): INSTALLS += target
          
          RESOURCES += \
              resource.qrc
          
          INCLUDEPATH += "C:\Users\path\Qt_c++\TitleCustomBar"
          
          
          J 1 Reply Last reply 1 Oct 2024, 12:47
          0
          • A Andrea_Venturelli
            1 Oct 2024, 12:37

            guys I added the .cpp file to the "SOURCE" param of the ".pro" file and now the error message has changed to the following:

            C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: debug/windowframe.o: in function `WindowFrame::on_maximize_tbnt_clicked()':
            C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: debug/windowframe.o: in function `WindowFrame::on_minimize_tbtn_clicked()':
            collect2.exe: error: ld returned 1 exit status
            C:\Users\path\Qt_c++\TrackInspector\windowframe.cpp:50: error: undefined reference to `WindowFrame::showNormalClicked()'
            :-1: error: C:\Users\path\Qt_c++\TrackInspector\build\Desktop_Qt_6_7_1_MinGW_64_bit-Debug/../../windowframe.cpp:54: undefined reference to `WindowFrame::maximizedClicked()'
            C:\Users\path\Qt_c++\TrackInspector\windowframe.cpp:61: error: undefined reference to `WindowFrame::minimizedClicked()'
            :-1: error: debug/windowframe.o:windowframe.cp:(.rdata$.refptr._ZTV11WindowFrame[.refptr._ZTV11WindowFrame]+0x0): undefined reference to `vtable for WindowFrame'
            :-1: error: [Makefile.Debug:83: debug/TrackInspector.exe] Error 1
            

            My .pro file look like this now:

            QT       += core gui
            
            greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
            
            CONFIG += c++17
            
            # You can make your code fail to compile if it uses deprecated APIs.
            # In order to do so, uncomment the following line.
            #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
            
            SOURCES += \
                main.cpp \
                trackmanager.cpp \
                windowframe.cpp
            
            HEADERS += \
                ../TitleCustomBar/profilebanner.h \
                trackmanager.h
                windowframe.h
            
            FORMS += \
                ../TitleCustomBar/profilebanner.ui \
                ../TitleCustomBar/windowframe.ui \
                trackmanager.ui
            
            # Default rules for deployment.
            qnx: target.path = /tmp/$${TARGET}/bin
            else: unix:!android: target.path = /opt/$${TARGET}/bin
            !isEmpty(target.path): INSTALLS += target
            
            RESOURCES += \
                resource.qrc
            
            INCLUDEPATH += "C:\Users\path\Qt_c++\TitleCustomBar"
            
            
            J Offline
            J Offline
            JonB
            wrote on 1 Oct 2024, 12:47 last edited by
            #7

            @Andrea_Venturelli said in Create Custom Window, with custom TitleBar:

            :-1: error: debug/windowframe.o:windowframe.cp:(.rdata$.refptr._ZTV11WindowFrame[.refptr._ZTV11WindowFrame]+0x0): undefined reference to `vtable for WindowFrame'

            • Clean everything out of build output directory and rebuild.
            • Does your WindowFrame class have/need Q_OBJECT macro?
            A 1 Reply Last reply 1 Oct 2024, 12:58
            0
            • J JonB
              1 Oct 2024, 12:47

              @Andrea_Venturelli said in Create Custom Window, with custom TitleBar:

              :-1: error: debug/windowframe.o:windowframe.cp:(.rdata$.refptr._ZTV11WindowFrame[.refptr._ZTV11WindowFrame]+0x0): undefined reference to `vtable for WindowFrame'

              • Clean everything out of build output directory and rebuild.
              • Does your WindowFrame class have/need Q_OBJECT macro?
              A Offline
              A Offline
              Andrea_Venturelli
              wrote on 1 Oct 2024, 12:58 last edited by
              #8

              @JonB I tryed deleting the Built folder and re-built but gave me the same error.

              I was tring to share the code but the page gave me the error of "spam message"

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Andrea_Venturelli
                wrote on 1 Oct 2024, 13:18 last edited by
                #9

                I set-up a gitHub account, here the code
                GitHub-repository

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Andrea_Venturelli
                  wrote on 1 Oct 2024, 14:34 last edited by Andrea_Venturelli 10 Jan 2024, 14:37
                  #10

                  the code is now working, seems one .cpp was still missed. but now I have this new problem where I loose che color background of the WindowFrame.

                  I Tryed removing the "backgroung-color" from the stylesheet of the WindowFrame.ui and replace it with "transparent".
                  After that I Tryed addign the stylesheet directly to the component and also to the TrackManager.ui targeting the WindowFrame {}

                  this is the result:
                  image.png

                  #include "trackmanager.h"
                  #include "ui_trackmanager.h"
                  
                  TrackManager::TrackManager(QWidget *parent)
                      : QWidget(parent)
                      , ui(new Ui::TrackManager)
                  {
                      ui->setupUi(this);
                  
                      QString TEMP_USER{"genericmail@gmail.it"};
                      QString TEMP_POWER{"Admin"};
                  
                      /*  Declaration status bar & title window  */
                      m_statusbar = new QStatusBar();
                      m_titlebar = new WindowFrame(TEMP_USER, TEMP_POWER, this);
                      m_titlebar->setStyleSheet("QWidget { background-color: \"#9b0000\";}");
                      connect(m_titlebar, &WindowFrame::maximizedClicked, this, &QWidget::showMaximized);
                      connect(m_titlebar, &WindowFrame::minimizedClicked, this, &QWidget::showMinimized);
                  
                      QVBoxLayout* window_layout = qobject_cast<QVBoxLayout*>(this->layout());
                      window_layout->insertWidget(0, m_titlebar);
                      window_layout->insertWidget(2, m_statusbar);
                  }
                  
                  QWidget
                  {
                  	background-color: "#7e7474";
                  }
                  
                  
                  #toolbar_wdg
                  {
                  	background-color: "#883d3d";
                  	border-radius: 12;
                  }
                  
                  
                  QToolButton
                  {
                  	background-color: white;
                  	border-radius: 8;
                  	border: 2 solid transparent;
                  
                  	outline: 0;
                  }
                  
                  QToolButton:checked
                  {
                  	background-color: rgb(239, 99, 102);
                  }
                  
                  QToolButton:hover
                  {
                  	border-color:  rgb(56, 132, 255);
                  }
                  
                  WindowFrame QWidget
                  {
                  	background-color: red;
                  }
                  
                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    Andrea_Venturelli
                    wrote on 2 Oct 2024, 10:06 last edited by
                    #11

                    The problem I had at the beginning was solved by including ALL the custom widget I had created ( file.h, file.cpp, file.ui) inside the final project directory;

                    To do so, you need to edit your final project "file.pro" and add the folder's paths where your custom widget live like so

                    "
                    inside .pro file
                    INCLUDEPATH += " insert/path/toyour/customWidgets "
                    "
                    After that, you can select "add existing file" directly from the Projects panel
                    306580a4-e3d8-47a7-8219-e9bcd3351b00-image.png .

                    On the other hand, I still struggle understanding how to create a custom-reusable-widget, which i defined its own stylesheet, but after it become a child widget, it will lose all the top level styling and only the components style will be applied (es. QPushButton, QLabel ecc..) because Qt erase the top level QWidget stylesheet for optimization purpose, or at least this is what I understand from reading posts

                    P 1 Reply Last reply 2 Oct 2024, 11:30
                    0
                    • A Andrea_Venturelli has marked this topic as solved on 2 Oct 2024, 10:06
                    • A Andrea_Venturelli
                      2 Oct 2024, 10:06

                      The problem I had at the beginning was solved by including ALL the custom widget I had created ( file.h, file.cpp, file.ui) inside the final project directory;

                      To do so, you need to edit your final project "file.pro" and add the folder's paths where your custom widget live like so

                      "
                      inside .pro file
                      INCLUDEPATH += " insert/path/toyour/customWidgets "
                      "
                      After that, you can select "add existing file" directly from the Projects panel
                      306580a4-e3d8-47a7-8219-e9bcd3351b00-image.png .

                      On the other hand, I still struggle understanding how to create a custom-reusable-widget, which i defined its own stylesheet, but after it become a child widget, it will lose all the top level styling and only the components style will be applied (es. QPushButton, QLabel ecc..) because Qt erase the top level QWidget stylesheet for optimization purpose, or at least this is what I understand from reading posts

                      P Offline
                      P Offline
                      Pl45m4
                      wrote on 2 Oct 2024, 11:30 last edited by
                      #12

                      @Andrea_Venturelli said in Create Custom Window, with custom TitleBar:

                      On the other hand, I still struggle understanding how to create a custom-reusable-widget, which i defined its own stylesheet, but after it become a child widget, it will lose all the top level styling and only the components style will be applied (es. QPushButton, QLabel ecc..) because Qt erase the top level QWidget stylesheet for optimization purpose, or at least this is what I understand from reading posts

                      Normally the last set and more specific settings should apply.

                      See here:

                      • https://doc.qt.io/qt-6/stylesheet-syntax.html
                        • https://doc.qt.io/qt-6/stylesheet-syntax.html#conflict-resolution
                        • https://doc.qt.io/qt-6/stylesheet-syntax.html#cascading
                        • https://doc.qt.io/qt-6/stylesheet-syntax.html#inheritance

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

                      ~E. W. Dijkstra

                      1 Reply Last reply
                      0

                      12/12

                      2 Oct 2024, 11:30

                      • Login

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