Added method to set column width to QTreeWidget (#523)
* Fixed slight error in dependencies installation command (Ubuntu) * Implemented setColumnWidth method for QTreeWidget * Added an example of using setColumnWidth method * Fixed doc error for setColumnWidth method.
This commit is contained in:
parent
e8c97e1938
commit
5f2bc51bbc
@ -31,6 +31,7 @@ class DLL_EXPORT QTreeWidgetWrap : public Napi::ObjectWrap<QTreeWidgetWrap> {
|
||||
Napi::Value insertTopLevelItems(const Napi::CallbackInfo &info);
|
||||
Napi::Value selectedItems(const Napi::CallbackInfo &info);
|
||||
Napi::Value setColumnCount(const Napi::CallbackInfo &info);
|
||||
Napi::Value setColumnWidth(const Napi::CallbackInfo &info);
|
||||
Napi::Value setHeaderLabel(const Napi::CallbackInfo &info);
|
||||
Napi::Value setHeaderLabels(const Napi::CallbackInfo &info);
|
||||
Napi::Value setItemWidget(const Napi::CallbackInfo &info);
|
||||
|
||||
@ -15,12 +15,11 @@ Napi::Object QTreeWidgetWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
env, CLASSNAME,
|
||||
{InstanceMethod("addTopLevelItem", &QTreeWidgetWrap::addTopLevelItem),
|
||||
InstanceMethod("addTopLevelItems", &QTreeWidgetWrap::addTopLevelItems),
|
||||
InstanceMethod("insertTopLevelItem",
|
||||
&QTreeWidgetWrap::insertTopLevelItem),
|
||||
InstanceMethod("insertTopLevelItems",
|
||||
&QTreeWidgetWrap::insertTopLevelItems),
|
||||
InstanceMethod("insertTopLevelItem",&QTreeWidgetWrap::insertTopLevelItem),
|
||||
InstanceMethod("insertTopLevelItems", &QTreeWidgetWrap::insertTopLevelItems),
|
||||
InstanceMethod("selectedItems", &QTreeWidgetWrap::selectedItems),
|
||||
InstanceMethod("setColumnCount", &QTreeWidgetWrap::setColumnCount),
|
||||
InstanceMethod("setColumnWidth", &QTreeWidgetWrap::setColumnWidth),
|
||||
InstanceMethod("setHeaderLabel", &QTreeWidgetWrap::setHeaderLabel),
|
||||
InstanceMethod("setHeaderLabels", &QTreeWidgetWrap::setHeaderLabels),
|
||||
InstanceMethod("setItemWidget", &QTreeWidgetWrap::setItemWidget),
|
||||
@ -153,6 +152,17 @@ Napi::Value QTreeWidgetWrap::setColumnCount(const Napi::CallbackInfo& info) {
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QTreeWidgetWrap::setColumnWidth(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int columns = info[0].As<Napi::Number>().Int32Value();
|
||||
int width = info[1].As<Napi::Number>().Int32Value();
|
||||
this->instance->setColumnWidth(columns, width);
|
||||
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QTreeWidgetWrap::setHeaderLabel(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
@ -5,9 +5,11 @@ import { DateFormat } from './lib/QtEnums';
|
||||
const { QMainWindow, QTreeWidgetItem, QTreeWidget, QDate, ItemDataRole, QDateTime } = require('./index');
|
||||
|
||||
const win = new QMainWindow();
|
||||
win.resize(500, 500);
|
||||
const tree = new QTreeWidget();
|
||||
tree.setSortingEnabled(true);
|
||||
tree.setHeaderLabels(['Date', 'Time']);
|
||||
tree.setHeaderLabels(['Date', 'Time', 'Test Column']);
|
||||
tree.setColumnWidth(1, 15); //Sets the size of the selected column (index, size).
|
||||
|
||||
const dates = [
|
||||
'11/22/1973 02:55:43 AM',
|
||||
|
||||
@ -115,6 +115,15 @@ export class QTreeWidget extends QAbstractScrollArea<QTreeWidgetSignals> {
|
||||
this.native.setColumnCount(columnCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the width of column of this QTreeWidget.
|
||||
* @param column The column index.
|
||||
* @param width The size of the columns.
|
||||
*/
|
||||
setColumnWidth(column: number, width: number): void {
|
||||
this.native.setColumnWidth(column, width);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the header label.
|
||||
* @param label The header label.
|
||||
|
||||
@ -34,7 +34,7 @@ Supported versions: Ubuntu 17.10 and up
|
||||
3. Make, GCC v7, pkg-config
|
||||
4. Qt (_Optional_): Make sure you followed the setup instructions from [Qode][qode_setup]
|
||||
|
||||
On Ubuntu: `$ sudo apt-get install pkg-config build-essentials` should install everything except Qt5.
|
||||
On Ubuntu: `$ sudo apt-get install pkg-config build-essential` should install everything except Qt5.
|
||||
|
||||
Note: If you are using your own version of Qt make sure to
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user