qt无.ui界面-------小例子

pro配置文件:
QT       += core gui
QT       += printsupport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    mainwindow.cpp \
    showwidget.cpp

HEADERS += \
    mainwindow.h \
    showwidget.h

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
main.c
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QImage>
#include <QLabel>
#include <QMenu>
#include <QMenuBar>
#include <QAction>
#include <QComboBox>
#include <QSpinBox>
#include <QToolBar>
#include <QFontComboBox>
#include <QToolButton>
#include <QTextCharFormat>
#include "showwidget.h"
class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void createActions();                        	//创建动作
    void createMenus();                           	//创建菜单
    void createToolBars();                      	//创建工具栏
    void loadFile(QString filename);
    void mergeFormat(QTextCharFormat);
private:
    QImage img;
    QString fileName;
    showwidget *myshowwidget;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include <QFileDialog>
#include <QFile>
#include <QTextStream>
#include <QPrintDialog>
#include <QPrinter>
#include <QPainter>
#include <QColorDialog>
#include <QColor>
#include <QTextList>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    setWindowTitle(tr("myexe"));

    myshowwidget = new showwidget(this);
    setCentralWidget(myshowwidget);

    createActions();
    createMenus();
    createToolBars();
//    if(img.load("1.jpg"))
//    {
//        myshowwidget->imageLabel->setPixmap(QPixmap::fromImage(img));
//    }
}
MainWindow::~MainWindow()
{
}
void MainWindow::createActions()
{
}
void MainWindow::createMenus()
{
}
void MainWindow::createToolBars()
{
}
showwidget.h
#ifndef SHOWWIDGET_H
#define SHOWWIDGET_H

#include <QWidget>
#include <QLabel>
#include <QTextEdit>
#include <QImage>
#include <QPushButton>

class showwidget : public QWidget
{
       Q_OBJECT
public:
    explicit showwidget(QWidget *parent = 0);
    QPushButton *button1;

private:

signals:

private slots:
    void getxml();

};

#endif // SHOWWIDGET_H
showwidget.cpp:
#include "showwidget.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <iostream>
#include <QLineEdit>
#include <QPushButton>
#include <QDebug>
showwidget::showwidget(QWidget *parent) :
    QWidget(parent)
{
//    imageLabel =new QLabel;   //用Qlabel展示图片
//    imageLabel->setScaledContents(true);
//    text =new QTextEdit;      //QTextEdit展示文本

    QVBoxLayout *mainLayout =new QVBoxLayout(this);

    QHBoxLayout *Layout1 =new QHBoxLayout(this);
    QHBoxLayout *Layout2 =new QHBoxLayout(this);
    QHBoxLayout *Layout3 =new QHBoxLayout(this);

    button1 = new QPushButton(this);
    button1->setText("get Kmeans.xml");
    Layout1->addWidget(button1);
    connect(button1,SIGNAL(clicked()),this,SLOT(getxml()));

    QLabel *label1 = new QLabel(this);
    label1->setText("input img1");
    QLineEdit *lineEdit1 = new QLineEdit(this);
    QPushButton *button2 = new QPushButton(this);
    button2->setText("to get target picture's name");
    Layout2->addWidget(label1);
    Layout2->addWidget(lineEdit1);
    Layout2->addWidget(button2);


    QLabel *label2 = new QLabel(this);
    label2->setText("input img2");
    QLineEdit *lineEdit2 = new QLineEdit(this);
    QPushButton *button3 = new QPushButton(this);
    button3->setText("look compared picture");
    Layout3->addWidget(label2);
    Layout3->addWidget(lineEdit2);
    Layout3->addWidget(button3);

//    mainLayout->addWidget(imageLabel);
//    mainLayout->addWidget(text);


    mainLayout->addLayout(Layout1);
    mainLayout->addLayout(Layout2);
    mainLayout->addLayout(Layout3);

    //connect(button1,SIGNAL(clicked()),this,SLOT(getxml()));
    //在这里加不行,识别不到槽函数
}

void showwidget::getxml()
{
    qDebug() << "getxml";
}
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值