qtableview

Qt Hide column in QTableView

匿名 (未验证) 提交于 2019-12-03 02:24:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to hide the ID column in the table view and i can't do that on my implementation. Can anyone help me? void MainWindow::on_actionClear_Search_triggered() { model = new QStandardItemModel(cars.size(),6,this); //create header createHeader(model); //set data to the table view populate(cars); ui->tableView->setColumnHidden(6,true); ui->tableView->setModel(model); } void MainWindow::createHeader(QStandardItemModel *model){ model->setHorizontalHeaderItem(0,new QStandardItem("Car")); model->setHorizontalHeaderItem(1, new QStandardItem("Type")

Qt QTableView how to have a checkbox only column

匿名 (未验证) 提交于 2019-12-03 01:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: We are using a QTableView with Qt 4.6.3, and need a column that only has a checkbox in each cell. We're using a custom subclass of QAbstractTableModel as the model for the QTableView . Right now, we have a checkbox by setting the Qt::ItemIsUserCheckable flag. But we can't figure out how to get rid of the blank textbox next to the checkbox! How can we make the column only have a checkbox, nothing else? 回答1: Here is a solution. For this to work properly, your column should not have the Qt::ItemIsEditable or Qt::ItemIsUserCheckable flags set.

How to filter Multiple column in Qtableview?

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using QtableView to show my logs and to filter them by column, QSortFilterProxyModel is used. If i filter one column using certain value, and with the filtered data, if i try to filter second column, last filter gets reset and data are displayed corresponding to filter on second column. I want to achieve multiple column filter on Qtableview. Code snippet: self.tableView = QTableView() self.model = QtGui.QStandardItemModel(self) self.proxy = QtGui.QSortFilterProxyModel(self) self.proxy.setSourceModel(self.model) self.tableView.setModel

Columns auto-resize to size of QTableView

匿名 (未验证) 提交于 2019-12-03 01:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am new to QT and I have just managed to make a QTableView work with my model. It has fixed 3 columns. When I open a window, it look ok but when i resize the window, the QTableView itself gets resized but columns' width remains the same. Is there any build-in way to make it work? I want columns to resize to fit the edges of QTableView every the the window gets resized. 回答1: There is a header flag to ensure that the QTableView's last column fills up its parent if resized. You can set it like so: table_view->horizontalHeader()-

QTableView: how to hover an entire row on mouse over?

匿名 (未验证) 提交于 2019-12-03 00:56:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I subclassed QTableView, QAbstractTableModel, and QItemDelegate. I am able to hover a single cell on mouse over: void SchedulerDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { ... if(option.showDecorationSelected &&(option.state & QStyle::State_Selected)) { QColor color(255,255,130,100); QColor colorEnd(255,255,50,150); QLinearGradient gradient(option.rect.topLeft(),option.rect.bottomRight()); gradient.setColorAt(0,color); gradient.setColorAt(1,colorEnd); QBrush brush(gradient); painter

QTableView和QSqlQueryModel的联合使用

匿名 (未验证) 提交于 2019-12-03 00:25:02
QSqlQueryModel 类为SQL结果集提供了只读数据模型。所以当前示例只显示不操作。 如果想在视图直接操作数据库内容,需要自己封装一个类且继承 QSqlQueryModel,重写里面的虚函数。 #include <QtSql/QSqlDatabase> #include <QtSql/QSqlQuery> #include <QtSql/QSqlQueryModel> QSqlDatabase * m_db ; QSqlQuery * m_qy ; QSqlQueryModel * m_model ; 第一步//打开数据库 m_db = new QSqlDatabase ; * m_db = QSqlDatabase :: addDatabase ( "QMYSQL" ); //链接MYSQL的驱动 m_db -> setHostName ( "127.0.0.1" ); //设置主机名 m_db -> setPort ( 3306 ); //配置端口号 m_db -> setDatabaseName ( "myDBtest" ); //打开"myDBtest"数据库 m_db -> setUserName ( "root" ); //账号 m_db -> setPassword ( "root" ); //密码 if ( m_db -> open ()){ qDebug

How to set row height of QTableView?

点点圈 提交于 2019-12-02 17:29:52
I have QTableView and QAbstractTableModel . I require rows to have height equal to 24. I know the only way to do this is by calling QTableView::setRowHeight . Since the model is dynamic it may be added new rows, but I don't want to call setRowHeight each time new row is added. How can I configure QTableView such that it uses the same height for new added rows or can a model be sent the height of rows? For Qt versions < 5 QHeaderView *verticalHeader = myTableView->verticalHeader(); verticalHeader->setResizeMode(QHeaderView::Fixed); verticalHeader->setDefaultSectionSize(24); For Qt versions >= 5

How to create filters for QTableView in PyQt

孤街醉人 提交于 2019-12-02 16:01:11
I am using QTableView to display data retrieved from QtSql.QSqlQuery I want to know how can i create filters for it like in excel. In the above image i need to get the filters for All heders (Sh_Code,SH_Seq,Stage) The filters will have unique values in of that column on which we can filter. Required result I need the Table view header with a dropbox listing all unique values in that column just like in excel below. No need of Top,Standard filter... as shown in image. Need only "All" and the unique "column items" This is from my .NET application, uploaded for more clarity Here is an example of

QSqlDatabase: How to avoid 'qt_sql_default_connection' still in use & duplicate connection related warning?

北城余情 提交于 2019-12-02 11:47:43
问题 Sorry if this is a trivial question but I have been trying to build a small .ui that used QSQLITE as database and that uses QTableView to show 4 columns on a default database file as example. I debugged the problem in every side, changed logical operations of the SQL and restructured the constructor in a more simple way but the error still stays. After finishing to set up all parameters I am getting this error: QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is

PyQt: How to sort QTableView columns of a excel file(strings and numericals and datetype)

允我心安 提交于 2019-12-02 08:37:04
This is a follow up question to: PyQt: How to sort QTableView columns(strings and numericals) Now I am planning to do the same sorting for the excel files Here is my Code: self.Upload = QtGui.QPushButton() self.Upload.clicked.connect(self.showOpenDialog) self.Table = QtGui.QPushButton() self.table.clicked.connect(self.LoadTable) def showOpenDialog(self): fileName = QtGui.QFileDialog.getOpenFileName(self, 'Open file', '/home') if (".xls" or ".xml" or ".xlsx" or ".xlsm") in fileName: with open(fileName, 'rb') as drate: self.Datas = pd.read_excel(drate, index_col=0) self.Loaded_File.clear() self