小仁熙

导航

Qt布局问题代码

#include "mainwindow.h"
//mainwindow.cpp
MainWindow::MainWindow()
{
    this->setWindowTitle("Sunny Media Player");
   // this->setWindowFlags(Qt::FramelessWindowHint|Qt::WindowTitleHint|Qt::WindowStaysOnTopHint|Qt::Tool );
    this->setFixedSize(270,150);
    this->setWindowIconText("Sunny Media");
    this->setWindowIcon(QIcon("/images/icon.png"));
    this->prograssBar=new QSlider(Qt::Horizontal,this);
    this->prograssBar->setFixedSize(250,30);
    this->play=new QPushButton("Play",this);
    this->pause=new QPushButton("Pause",this);
    this->stop=new QPushButton("Stop",this);

    this->prograssBar->setAcceptDrops(false);
    this->prograssBar->setRange(0,1000);

    this->mainLayout=new QVBoxLayout();
    this->downLayout=new QHBoxLayout();

    this->mainLayout->addWidget(this->prograssBar);
    this->downLayout->addWidget(this->play);
    this->downLayout->addWidget(this->pause);
    this->downLayout->addWidget(this->stop);
    this->mainLayout->addLayout(this->downLayout);
    this->setLayout(this->mainLayout);
}

mainwindow.h文件

#pragma once
#include<QtGui>
#include<QtCore>
#include<QMainWindow>

class MainWindow : public QMainWindow{
    Q_OBJECT

   public:
    MainWindow();
private:
    QSlider *prograssBar;
    QPushButton *play;
    QPushButton *pause;
    QPushButton *stop;
    QHBoxLayout *downLayout;
    QVBoxLayout *mainLayout;
};

main.cpp

#include<QtGui>
#include<QtCore>
#include<QDebug>
#include"mainwindow.h"
int main(int argc,char * argv[])
{
    QApplication *app=new QApplication(argc,argv);
    app->setApplicationName("Sunny Player");
    MainWindow m;
    m.show();

    return app->exec();
}

 

posted on 2013-01-30 14:01  堕落77天使  阅读(617)  评论(0编辑  收藏  举报