逛奔的蜗牛

我不聪明,但我会很努力

   ::  :: 新随笔 ::  ::  :: 管理 ::
#ifndef LISTWINDOW_H_
#define LISTWINDOW_H_

#include 
<QDialog>

class QPushButton;
class QListWidget;
class QWidget;

class ListWindow : public QDialog {
    Q_OBJECT
public:
    ListWindow(QWidget 
*parent = 0);
    virtual 
~ListWindow();

public slots:
    
void moveLeft();
    
void moveRight();
    
private:
    QPushButton 
*moveLeftButton;
    QPushButton 
*moveRightButton;
    QListWidget 
*leftList;
    QListWidget 
*rightList;
}
;

#endif 
/*LISTWINDOW_H_*/

#include "ListWindow.h"
#include 
<QPushButton>
#include 
<QListWidget>
#include 
<QWidget>
#include 
<QHBoxLayout>
#include 
<QVBoxLayout>
#include 
<QGridLayout>
#include 
<QStringList>
#include 
<QListWidgetItem>

ListWindow::ListWindow(QWidget 
*parent) :
    QDialog(parent) 
{
    QGridLayout 
*gridLayout = new QGridLayout();
    gridLayout
->addWidget(leftList = new QListWidget(), 0031);
    gridLayout
->addWidget(moveLeftButton = new QPushButton("<<"), 0111);
    gridLayout
->addWidget(moveRightButton = new QPushButton(">>"), 1111);
    gridLayout
->addWidget(rightList = new QListWidget(), 0231);
    
    QObject::connect(moveLeftButton, SIGNAL(clicked()), 
this, SLOT(moveLeft()));
    QObject::connect(moveRightButton, SIGNAL(clicked()), 
this, SLOT(moveRight()));
    
    QStringList items;
    items 
<< "One" << "Two" << "Three" << "Four" << "Five" << "Sechs"
            
<< "Sieben" << "One" << "Two" << "Three" << "Four" << "Five"
            
<< "Sechs" << "Sieben";
    leftList
->addItems(items);
    
    
this->setLayout(gridLayout);
}


ListWindow::
~ListWindow() {
}


void ListWindow::moveLeft() {
    
//    if (rightList->currentItem() == 0) {
    
//        return;
    
//    }
    
//    
    
//    QString text = rightList->currentItem()->text();
    
//    delete rightList->currentItem();
    
//    leftList->addItem(text);
    
    
// The takeItem() method is used to remove an Item form one list without 
    
// having to delete it. TakeItem() no deleting or no creating, more efficient.
    if (rightList->selectedItems().count() != 1{
        
return;
    }

    
    QListWidgetItem 
*item = rightList->takeItem(rightList->currentRow());
    leftList
->addItem(item);
}


void ListWindow::moveRight() {
    
//    if (leftList->currentItem() == 0) {
    
//        return;
    
//    }
    
//    
    
//    QString text = leftList->currentItem()->text();
    
//    delete leftList->currentItem();
    
//    rightList->addItem(text);

    
if (leftList->selectedItems().count() != 1{
        
return;
    }

    
    QListWidgetItem 
*item = leftList->takeItem(leftList->currentRow());
    rightList
->addItem(item);
}


posted on 2008-03-22 01:24 逛奔的蜗牛 阅读(3990) 评论(0)  编辑 收藏 引用 所属分类: Qt

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理