C++ GUI Qt4编程(12)-6.1FindFileDialog
生活随笔
收集整理的這篇文章主要介紹了
C++ GUI Qt4编程(12)-6.1FindFileDialog
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1. 主要介紹了QGridLayout, QHBoxLayout, QVBoxLayout3種布局管理器的使用方法。
2. 在linux中,繼承自QDialog的對話框,沒有最大化、最小化、關閉按鈕,如果需要這3個按鈕,
??? 需要增加:? setWindowFlags(Qt::Widget);
??? 在windows中,即使不加:setWindowFlags(Qt::Widget); 也會有最大化、最小化、關閉按鈕。
3. findfiledialog.h
1 /**/ 2 #ifndef FINDFILEDIALOG_H 3 #define FINDFILEDIALOG_H 4 5 #include <QDialog> 6 7 class QLabel; 8 class QLineEdit; 9 class QPushButton; 10 class QCheckBox; 11 class QTableWidget; 12 class QHBoxLayout; 13 class QVBoxLayout; 14 class QGridLayout; 15 16 class FindFileDialog : public QDialog 17 { 18 Q_OBJECT 19 20 public: 21 FindFileDialog(QWidget *parent = 0); 22 23 private: 24 QLabel *namedLabel; 25 QLabel *lookInLabel; 26 QLineEdit *namedLineEdit; 27 QLineEdit *lookInLineEdit; 28 QCheckBox *subfoldersCheckBox; 29 QTableWidget *tableWidget; 30 QLabel *messageLabel; 31 32 QPushButton *findButton; 33 QPushButton *stopButton; 34 QPushButton *closeButton; 35 QPushButton *helpButton; 36 37 QGridLayout *leftLayout; 38 QVBoxLayout *rightLayout; 39 QHBoxLayout *mainLayout; 40 }; 41 42 43 #endif4. findfiledialog.cpp
1 /**/ 2 #include "findfiledialog.h" 3 4 #include <QLabel> 5 #include <QLineEdit> 6 #include <QPushButton> 7 #include <QCheckBox> 8 #include <QTableWidget> 9 #include <QHBoxLayout> 10 #include <QVBoxLayout> 11 #include <QGridLayout> 12 13 FindFileDialog::FindFileDialog(QWidget *parent) 14 : QDialog(parent) 15 { 16 namedLabel = new QLabel(tr("&Named:")); 17 namedLineEdit = new QLineEdit; 18 namedLabel->setBuddy(namedLineEdit); 19 20 lookInLabel = new QLabel(tr("&Look in:")); 21 lookInLineEdit = new QLineEdit; 22 lookInLabel->setBuddy(lookInLineEdit); 23 24 subfoldersCheckBox = new QCheckBox(tr("Include subfolders")); 25 26 QStringList labels; 27 labels << tr("Name") << tr("In Folder") 28 << tr("Size") << tr("Modified"); 29 30 tableWidget = new QTableWidget; 31 tableWidget->setColumnCount(4); 32 tableWidget->setHorizontalHeaderLabels(labels); 33 34 messageLabel = new QLabel(tr("0 files found")); 35 messageLabel->setFrameShape(QFrame::Panel); 36 messageLabel->setFrameShadow(QFrame::Sunken); 37 38 /* QGridLayout 39 void addWidget(QWidget * widget, 40 int fromRow,int fromColumn, 41 int rowSpan,int columnSpan, 42 Qt::Alignment alignment = 0) 43 */ 44 leftLayout = new QGridLayout; 45 leftLayout->addWidget(namedLabel, 0, 0); 46 leftLayout->addWidget(namedLineEdit, 0, 1); 47 leftLayout->addWidget(lookInLabel, 1, 0); 48 leftLayout->addWidget(lookInLineEdit, 1, 1); 49 /*subfoldersCheckBox的位置坐標(2, 0),占1行,占2列*/ 50 leftLayout->addWidget(subfoldersCheckBox, 2, 0, 1, 2); 51 leftLayout->addWidget(tableWidget, 3, 0, 1, 2); 52 leftLayout->addWidget(messageLabel, 4, 0, 1, 2); 53 54 55 findButton = new QPushButton(tr("&Find")); 56 stopButton = new QPushButton(tr("&Stop")); 57 closeButton = new QPushButton(tr("&Close")); 58 helpButton = new QPushButton(tr("&Help")); 59 60 connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); 61 62 rightLayout = new QVBoxLayout; 63 rightLayout->addWidget(findButton); 64 rightLayout->addWidget(stopButton); 65 rightLayout->addWidget(closeButton); 66 rightLayout->addStretch(); 67 rightLayout->addWidget(helpButton); 68 69 mainLayout = new QHBoxLayout; 70 mainLayout->addLayout(leftLayout); 71 mainLayout->addLayout(rightLayout); 72 73 setLayout(mainLayout); 74 setWindowTitle(tr("Find Files or Folders")); 75 /*在linux中,繼承自QDialog的對話框沒有最大化最小化和關閉按鈕*/ 76 setWindowFlags(Qt::Widget); /*在linux中讓對話框有最大最小和關閉按鈕*/ 77 }5. main.cpp
1 /**/ 2 #include <QApplication> 3 #include "findfiledialog.h" 4 5 int main(int argc, char *argv[]) 6 { 7 QApplication app(argc, argv); 8 9 FindFileDialog dialog; 10 dialog.show(); 11 12 return app.exec(); 13 }6. 不帶關閉按鈕:
帶關閉按鈕:
轉載于:https://www.cnblogs.com/seifguo/p/7368062.html
總結
以上是生活随笔為你收集整理的C++ GUI Qt4编程(12)-6.1FindFileDialog的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 将M进制的数转换为N进制的数(java)
- 下一篇: s3c2440移植MQTT