Results 1 to 5 of 5

Thread: Add custom widget to a mainwindow

  1. #1
    Join Date
    Jan 2013
    Posts
    43
    Thanks
    27
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Add custom widget to a mainwindow

    Supose i have a QWidget ...
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2013-05-06T14:58:35
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core gui
    8.  
    9. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    10.  
    11. TARGET = widget
    12. TEMPLATE = app
    13.  
    14.  
    15. SOURCES += main.cpp\
    16. widget.cpp
    17.  
    18. HEADERS += widget.h
    19.  
    20. FORMS += widget.ui
    To copy to clipboard, switch view to plain text mode 
    ... and a QMainWindow ...
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2013-05-06T15:00:31
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core gui
    8.  
    9. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    10.  
    11. TARGET = mainwindow
    12. TEMPLATE = app
    13.  
    14.  
    15. SOURCES += main.cpp\
    16. mainwindow.cpp
    17.  
    18. HEADERS += mainwindow.h
    19.  
    20. FORMS += mainwindow.ui
    To copy to clipboard, switch view to plain text mode 
    Both were created separately.

    Now i want to use the Widget as the centralWidget of the mainwindow.
    If i copy the widget folder to the mainwindow folder, what is the next step to integrate them?

  2. The following user says thank you to aguleo for this useful post:


  3. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,530
    Thanked 281 Times in 276 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Add custom widget to a mainwindow

    No, You have two project files. Why ? Just create one project file integrating all cpp, h and ui files.The rest is a simple C++.

  4. The following 2 users say thank you to Lesiok for this useful post:

    aguleo (6th May 2013)

  5. #3
    Join Date
    Jan 2013
    Posts
    43
    Thanks
    27
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Add custom widget to a mainwindow

    I was thinking of renaming the .pro to .pri, in the widget, and then make the necessary changings.
    After that, i should try to promote the widget and set it a central widget.
    The idea was to keep them separated as mush as possible!

  6. The following user says thank you to aguleo for this useful post:


  7. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Add custom widget to a mainwindow

    Now i want to use the Widget as the centralWidget of the mainwindow.
    If i copy the widget folder to the mainwindow folder, what is the next step to integrate them?
    Add the windget files to the mainwindow project
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  8. The following 2 users say thank you to Santosh Reddy for this useful post:

    aguleo (6th May 2013)

  9. #5
    Join Date
    Jan 2013
    Posts
    43
    Thanks
    27
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Add custom widget to a mainwindow

    Add the windget files to the mainwindow project
    But this can be done via a pri file...right?


    Added after 1 4 minutes:


    It works by doing:
    1 - placing the widget folder inside the mainwindows folder;
    2 - adding include(widget/widget.pri) to mainwindow.pro
    3 - renamming the widget.pro to widget.pri and changing it's content to:
    Qt Code:
    1. SOURCES += widget/widget.cpp
    2.  
    3. HEADERS += widget/widget.h
    4.  
    5. FORMS += widget/widget.ui
    To copy to clipboard, switch view to plain text mode 

    It gives me a good organization in QtCreator but, after making all this changes, it might be better to simply add everything to the mainwindow.pro
    Last edited by aguleo; 7th May 2013 at 14:49.

  10. The following user says thank you to aguleo for this useful post:


Similar Threads

  1. Replies: 0
    Last Post: 19th March 2012, 19:09
  2. Replies: 0
    Last Post: 6th November 2011, 09:22
  3. Replies: 9
    Last Post: 12th November 2010, 14:50
  4. Replies: 10
    Last Post: 29th May 2010, 18:42
  5. Add a custom widget in code to a MainWindow
    By Steff in forum Qt Programming
    Replies: 2
    Last Post: 19th November 2009, 07:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.