Some basic operations under QT Designer

Source: Internet
Author: User
Tags qt designer

First QT Designer programming (under Visual stdio)

< a >, create a new QT Console application project in VS, open the designer and start laying out your window.

< two >, open Designer, will let you create a new form file, you can choose to inherit from Qdialog, Qwidget, Qmainwindow, qframe, etc.

< three >, after the last step (we are listed as Qmainwindow):

1, you can directly add the menu bar, the menu bar under the action event

2. Add Toolbar: Select Add Toolbar (you can add multiple) by right-click in the window margin. Is there any text under icon icons: Set toolbar properties: Toolbuttonstyle to Toolbuttontextundericon/toolbuttonicononly. The code is: Toolbar->settoolbuttonstyle (Qt::toolbuttontextundericon);

3. Add icon icons to the toolbar:
(1), create a new QRC file: such as MAINWINDOW.QRC (location: At the root of your project), then the code is as follows:

<RCC>
<qresource prefix= ":/qt_designer_test" >
<file>Icon/open.png</file>
</qresource>
</RCC>
Note: The icon folder is placed in the root directory, and Qt_designer_test is the project name folder.
(2), add resource file (QRC file):
Select Action Editor, create a new action, icon bar, select Resource, edit resource, select the icon you want, and then OK
(3), then, drag the newly created Action (action) to the toolbar

< four >, put the controls you need on the Qmainwindow, go back to vs in a compilation, get a ui_mainiwindow.h file

< five >, in the project, own a new mainwindow.h and mainwindow.cpp
Mainwindow.h

#ifndef Cwindow_h
#define Cwindow_h

#include "Generatedfiles/ui_mainwindow.h"
#include <QMainWindow>

Class Cwindow:public Qmainwindow
{
Q_object

Public
CWindow ();

Private
Ui::mainwindow UI;
};

#endif

Mainwindow.cpp

#include "Window.h"

Cwindow::cwindow ()
{
UI.SETUPUI (this);
Connect (Ui.actionexit, SIGNAL (triggered ()), this, SLOT (Close ()));
}

< six >, in the main function, add:
MainWindow Manwin;
Mainwin.show ();
Compile and run, it's OK.

Note: You can change the variable name of each control in the designer. If you want to add a Qglwidget class on Qmainwindow, the following:

Class Glarea:public Qglwidget

{
Public
Q_object

Public
Glarea (Qwidget *parent = 0);
~glarea (void);

void Initializegl ();
void Resizegl (int w, int h);
void Paintgl ();

}

Glarea::glarea (Qwidget *parent): Qglwidget (/*qglformat (qgl::D oublebuffer | QGL::D Epthbuffer | qgl::samplebuffers), */parent)

Class Mainwindow:public Qmainwindow
{
Q_object

Public
MainWindow (Qwidget *parent = 0, Qt::wflags flags = 0);
~mainwindow ();

}

Mainwindow::mainwindow (Qwidget *parent, qt::wflags flags)
: Qmainwindow (parent, flags)
{
cout << "MainWindow constructed" << Endl;
UI.SETUPUI (this);
area = new Glarea (this);//glarea is an inherited Qglwidget class
Setcentralwidget (area);

}

Some basic operations under QT Designer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.