QT4.1 setSelectionBehavior klappt nicht bei QTableWidget



  • Hallo zusammen,

    Ich habe ein Table Widget mit 2 Columns.
    wie kann ich erreichen,daß mein TableWidget bei der Selektion des Columns 0 gleichzeitig auch den Column1 auswählt ?

    bisheriger Code:

    #include "test01.h"
    #include <QHeaderView>
    #include <QTableWidget>
    #include <QAbstractItemView>
    
    test01::test01(QWidget *parent, Qt::WFlags flags)
        : QMainWindow(parent, flags)
    {
    	ui.setupUi(this);
    
    	ui.domainTxt->setGeometry(10,10,207,22);
    	setFixedSize(520,260);
    
    	ui.addBtn->setText("Hinzufügen");
    	ui.updateBtn->setText("Ändern");
    	ui.delBtn->setText("Löschen");
    
    	setTabOrder(ui.domainTxt,ui.IpTxt);
    	setTabOrder(ui.IpTxt,ui.addBtn);
    	setTabOrder(ui.addBtn,ui.myTable);
    
    	ui.myTable->setColumnCount(2);
        ui.myTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
    	ui.myTable->verticalHeader()->hide();
    	ui.myTable->horizontalHeader()->hide();
    	ui.myTable->setShowGrid(false);
    
    	ui.myTable->setSelectionBehavior( QAbstractItemView::SelectRows );
    	ui.myTable->setSelectionMode( QAbstractItemView::SingleSelection );
    
    }
    
    test01::~test01()
    {
    
    }
    
    void test01::on_addBtn_clicked()
    {
    	QString s1 = ui.domainTxt->text();
    	QString s2 = ui.IpTxt->text();
    
    	QTableWidgetItem *file1 = new QTableWidgetItem(s1);
    	file1->setFlags(Qt::ItemIsEnabled);
    	QTableWidgetItem *file2 = new QTableWidgetItem(s2);
    	file2->setFlags(Qt::ItemIsEnabled);
    
    	int row = ui.myTable->rowCount();
    	ui.myTable->insertRow(row);
    	ui.myTable->setItem(row, 0, file1);
    	ui.myTable->setItem(row, 1, file2);
    }
    
    void test01::on_myTable_currentItemChanged()
    {
    	int row = ui.myTable->currentRow();
    	ui.domainTxt->setText(ui.myTable->item(row,0)->text());
    	ui.IpTxt->setText(ui.myTable->item(row,1)->text());
    }
    

Log in to reply