Results 1 to 9 of 9

Thread: Why don't I have any code related to .ui in .cpp file?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Question Why don't I have any code related to .ui in .cpp file?

    Hi, I am really new in Qt. I created a GUI application project and I am trying to edit the buttons I created in the Designer but where are they created in the code? I can't see anything related to it in .cpp files. I assumed that it would be like Visual Studio you know when I double click on sth I can write the events of it etc. In my mainwindow.cpp there is only

    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    How do I change the buttons or anything I created with this? I have a main.cpp other than this.

  2. #2
    Join Date
    Dec 2010
    Location
    Germany
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Why don't I have any code related to .ui in .cpp file?

    The UI part is stored in the .ui xml file, e. g. mainwindow.ui (see Qt documentation). It is loaded by the ui object with the line:

    Qt Code:
    1. ui->setupUi(this);
    To copy to clipboard, switch view to plain text mode 

    You are able to edit this .ui file by hand, but espacially for someone new to Qt, it is better to edit it with Qt Creator (the Qt IDE) or Qt Designer.

  3. #3
    Join Date
    Dec 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why don't I have any code related to .ui in .cpp file?

    Quote Originally Posted by ireas View Post
    The UI part is stored in the .ui xml file, e. g. mainwindow.ui (see Qt documentation). It is loaded by the ui object with the line:

    Qt Code:
    1. ui->setupUi(this);
    To copy to clipboard, switch view to plain text mode 

    You are able to edit this .ui file by hand, but espacially for someone new to Qt, it is better to edit it with Qt Creator (the Qt IDE) or Qt Designer.
    How do I handle the events by hand like Visual Studio with C#? I want to be able to change one panel with button clicks, how can I handle it? The other parts of the page should remain the same like Facebook (only the middle area changes by clicking buttons etc.)

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    62
    Thanked 260 Times in 246 Posts

    Default Re: Why don't I have any code related to .ui in .cpp file?

    Read about signals and slots, documentation here.

  5. #5
    Join Date
    Dec 2010
    Location
    Germany
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Why don't I have any code related to .ui in .cpp file?

    Maybe it is helpful for you to know that all objects you create with the designer are members of the ui object. So if you create a object named lineEdit, you may access it with ui->lineEdit. Please read the Qt documentation, examples and tutorials for more information.

  6. #6
    Join Date
    Dec 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why don't I have any code related to .ui in .cpp file?

    Thank you now I am writing as ui-> etc. But I still couldn't figure out how I can change the middle part only. When I click Performance, I should get Performance Edit in the middle, when I click Home, I should get the table of some stuff. How can I manage this? Can't I do this with ui designer and then edit it? Or should I do it all in the code?

  7. #7
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: Why don't I have any code related to .ui in .cpp file?

    Its all done for you by uic - which takes your .ui file created by designer and generates code which it places into a header file. The code in this header file generates the ui for you.

    However, you shouldn't edit this header file yourself.

    What are you trying to do exactly - what do you mean by "changing the middle part only" - what middle part? We don't have the design of your ui, we have no idea of what you are talking about.

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Why don't I have any code related to .ui in .cpp file?

    Related thread with vague UI description here:
    http://www.qtcentre.org/threads/3663...button-clicked

  9. #9
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    10
    Thanked 31 Times in 25 Posts

    Default Re: Why don't I have any code related to .ui in .cpp file?

    Hi Ada,

    For your 'middle' part :
    - open your form in the form editor
    - from the controls toolbar under 'containers', add a 'Frame' on the left side of the form, a Stacked Widget in the middle, and then again a Frame on the right
    - apply a Horizontal layout to the form. This arranges the 2 frames and stackedwidget in 3 colums. Adjust size properties as you like
    - to the Stacked Widget, add 3 pages for home, performance, edit
    - in the left frame, add 3 buttons for home, performance, edit
    - add code to the 3 buttons to select the correct page in the Stacked Widget

    You should be able to figure out how to do each of these steps by yourself.

    Best regards,
    Marc

Similar Threads

  1. will this piece of code related to phonon works?
    By Lakshmi.Bollavaram in forum Installation and Deployment
    Replies: 1
    Last Post: 20th November 2009, 08:57
  2. compile source code file
    By eva in forum Qt Programming
    Replies: 6
    Last Post: 16th March 2009, 11:15
  3. Text file to PDF convertion using C++ code
    By joseph in forum General Discussion
    Replies: 2
    Last Post: 21st August 2008, 01:28
  4. Related to header file
    By merry in forum Qt Programming
    Replies: 2
    Last Post: 10th May 2007, 13:03
  5. Where is code file
    By safknw in forum Qt Tools
    Replies: 21
    Last Post: 20th June 2006, 10:08

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
  •  
Qt is a trademark of The Qt Company.