Hi,
here is a minimal example that produces the described issue. Btw I'm using Qt 5.4.1.
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTableWidget>
{
Q_OBJECT
public:
~MainWindow();
private:
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTableWidget>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private:
QTableWidget *table;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
){
setFixedSize(550,200);
// Setup Table
table->setColumnCount(5);
table->setRowCount(5);
table->setSortingEnabled(true);
// filling the table
for(int i=0; i<table->rowCount(); i++)
// sort table
table->sortByColumn(0,Qt::AscendingOrder);
// Add table to window widget
setCentralWidget(table);
}
MainWindow::~MainWindow()
{
delete table;
}
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setFixedSize(550,200);
// Setup Table
table = new QTableWidget(this);
table->setColumnCount(5);
table->setRowCount(5);
table->setSelectionMode(QAbstractItemView::SingleSelection);
table->setSelectionBehavior(QAbstractItemView::SelectRows);
table->setSortingEnabled(true);
// filling the table
for(int i=0; i<table->rowCount(); i++)
table->setItem(i,0,new QTableWidgetItem(QString::number(i+1)));
// sort table
table->sortByColumn(0,Qt::AscendingOrder);
// Add table to window widget
setCentralWidget(table);
}
MainWindow::~MainWindow()
{
delete table;
}
To copy to clipboard, switch view to plain text mode
When I change the number in the first cell from 1 to 6 I got the selection problem.
Bookmarks