PDA

View Full Version : A Bug in Qt?



calmspeaker
19th November 2008, 10:33
I use a QTableView and a model subclassed QAbstractTableModel to display the items which is increasing per second. And in order to display the items number which is selected by user, I use QItemSelectionModel.The attachment complete the task.But there is a strange bug.
The selction setting of tableview is

ui.tableView->setSelectionBehavior(QAbstractItemView::SelectRows );
ui.tableView->setSelectionMode(QAbstractItemView::MultiSelection );
And the critical codes which bring bug are

QHeaderView* VerHeaderView = ui.tableView->horizontalHeader();
VerHeaderView->swapSections(1,2); //this is critial for the behavior of m_selectionModel
If I selected items in the tableview by push down left button of mouse,draw diagonal line of a rectangel,the release the button. The displayed number of selected items is totally wrong.

If deleted the critical codes, repeat the selection in the same way. This time, the displayed number is right. I want to know, where is the mistake?

calmspeaker
20th November 2008, 02:05
Could anyone give me a clue? Or did not I describe the problem clearly?

ascii
20th November 2008, 08:23
Qt Code:
QHeaderView* VerHeaderView = ui.tableView->horizontalHeader();

i think you dont allocate memory field for VerHeaderView. I dont use before but i can say something.

you try

QHeaderView VerHeaderView(ui.tableView->horizontalHeader());

or
QHeaderView* VerHeaderView = new QHeaderView(ui.tableView->horizontalHeader());

or

QHeaderView* VerHeaderView = new QHeaderView();
VerHeaderView = ui.tableView->horizontalHeader(); // if there is a set function, you can use

spirit
20th November 2008, 08:27
Qt Code:
QHeaderView* VerHeaderView = ui.tableView->horizontalHeader();

i think you dont allocate memory field for VerHeaderView. I dont use before but i can say something.

you try

QHeaderView VerHeaderView(ui.tableView->horizontalHeader());

or
QHeaderView* VerHeaderView = new QHeaderView(ui.tableView->horizontalHeader());

or

QHeaderView* VerHeaderView = new QHeaderView();
VerHeaderView = ui.tableView->horizontalHeader(); // if there is a set function, you can use

you are wrong


QHeaderView * QTableView::horizontalHeader () const
Returns the table view's horizontal header.

this code works perfectly


QHeaderView* VerHeaderView = ui.tableView->horizontalHeader();

you can investigate sources of QTableView and find that headers are created in a table. :)

ascii
20th November 2008, 09:07
;)i had said i don't use before :)

calmspeaker
20th November 2008, 09:48
er, what about my question?

aamer4yu
21st November 2008, 05:37
cant reproduce...
can u tell more steps in detail ?

calmspeaker
26th November 2008, 02:32
what do u mean?The codes I attached cannot be compiled correctly or what?

spirit
26th November 2008, 07:20
he meant that could be nice if you post compilable project not snippet of code.

calmspeaker
27th November 2008, 03:40
he meant that could be nice if you post compilable project not snippet of code.

My attched files is enough to get a "exe"!:confused:

aamer4yu
27th November 2008, 05:33
I meant I didnt get any errors while running the program....
it will be nice if u cud attach some snapshots showing the prob...

calmspeaker
27th November 2008, 07:10
I want to use the lineedit in the bottom of the window to show the row number whcih is selected by the user! But the number is not always right.If u select the row just by one mouse btn click, the number is right. If u select the rows by pushdown your left mouse btn and draw diagonal line of a rectangel,then release the button, the rows in the rectangel would be selected, but the number which is showed in the lineedit is totally wrong.
Together with my original post, I hope I make myself clear.

spirit
27th November 2008, 07:31
try to use something like this


...
connect(ui.tableView, SIGNAL(entered(const QModelIndex &)), SLOT(entered(const QModelIndex &)));

}

void MyWidget::entered(const QModelIndex &index)
{
if (!index.isValid())
return;
ui.lineEdit->setText(QString("%1").arg(m_selectionModel->selectedRows().size()));
}

calmspeaker
27th November 2008, 08:46
it seems does not work......

calmspeaker
27th November 2008, 08:49
it seems does not work......
And the signal does not meet the logic demand.

spirit
27th November 2008, 09:04
this code returs correct value of selected rows. maybe you do something wrong or I don't understand properly what do you want to achieve.