Resizing Treeview icon
-
Hey, I am new to QT, i have been playing around with widgets now, more specifically those i intend to use for a project i am working on, i wanted to know if there was a way to resize the icon in a Treeview, i think it might be possible by fiddling with the drawing of the widgets, but like i said i am new and i don't know much about that, so i wanted to know if could do it without resorting to a custom drawing
Here is the relevant part of the code:-
mainwindow.ui:-
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>250</x>
<y>100</y>
<width>84</width>
<height>24</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">QPushButton {
border: 1px solid ;
border-radius: 6px;}</string>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
<widget class="QPlainTextEdit" name="plainTextEdit">
<property name="geometry">
<rect>
<x>80</x>
<y>130</y>
<width>101</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QTextEdit" name="textEdit">
<property name="geometry">
<rect>
<x>110</x>
<y>40</y>
<width>104</width>
<height>70</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>380</x>
<y>70</y>
<width>254</width>
<height>24</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">
QLineEdit {
border: 1px solid ;
border-radius: 6px;}
</string>
</property>
</widget>
<widget class="QScrollArea" name="scrollArea">
<property name="geometry">
<rect>
<x>250</x>
<y>150</y>
<width>120</width>
<height>181</height>
</rect>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>118</width>
<height>179</height>
</rect>
</property>
<widget class="QCheckBox" name="checkBox">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>78</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>CheckBox</string>
</property>
</widget>
<widget class="QToolButton" name="toolButton">
<property name="geometry">
<rect>
<x>40</x>
<y>40</y>
<width>23</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
<widget class="QScrollBar" name="verticalScrollBar">
<property name="geometry">
<rect>
<x>90</x>
<y>10</y>
<width>16</width>
<height>160</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</widget>
</widget>
<widget class="QRadioButton" name="radioButton">
<property name="geometry">
<rect>
<x>90</x>
<y>270</y>
<width>91</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>RadioButton</string>
</property>
</widget>
<widget class="QListWidget" name="listWidget">
<property name="geometry">
<rect>
<x>470</x>
<y>150</y>
<width>256</width>
<height>151</height>
</rect>
</property>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
<property name="icon">
<iconset>
<disabledon>../../../../../../Pictures/photos/R-4.png</disabledon>
<selectedoff>../../../../../../Pictures/photos/R-1.png</selectedoff>
<selectedon>../../../../../../Pictures/photos/R-3.png</selectedon>
</iconset>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
<item>
<property name="text">
<string>New Item</string>
</property>
</item>
</widget>
<widget class="QTreeView" name="treeView">
<property name="geometry">
<rect>
<x>40</x>
<y>300</y>
<width>511</width>
<height>201</height>
</rect>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
mainwindow.cpp:-
#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
ui = new Ui::MainWindow;
ui->setupUi(this);
//QStandardItemModel model;QStandardItemModel* mymodel = new QStandardItemModel; QFont Font; Font.setBold(true); Font.setPointSize(10); // Create items (QStandardItem objects) QStandardItem *item1 = new QStandardItem(); item1->setText("John"); item1->setFont(Font); item1->setEditable(false); item1->setSizeHint(QSize(10,30)); QIcon Icon(R"(C:\Users\Twenty-fifth night\Pictures\photos\R-1.png)"); Icon.actualSize(QSize(100,100)); item1->setIcon(Icon); item1->setSizeHint(QSize(50,50)); QStandardItem *SubItem1_1 = new QStandardItem("Yeah, I saw it too...."); SubItem1_1->setSelectable(false); SubItem1_1->setEditable(false); item1->setToolTip("Yeah, I saw it too...."); item1->appendRow(SubItem1_1); mymodel->appendRow(item1); QStandardItem *item2 = new QStandardItem("This is item two"); mymodel->appendRow(item2); QStandardItem *item3 = new QStandardItem("This is item three"); mymodel->appendRow(item3); QStandardItem *item4 = new QStandardItem("This is item two"); mymodel->appendRow(item4); QStandardItem *item5 = new QStandardItem("This is item three"); mymodel->appendRow(item5); // ui->treeView->setResizeMode(QListView::Adjust); ui->treeView->setWordWrap(true); ui->treeView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); ui->treeView->setModel(mymodel); ui->treeView->setHeaderHidden(true); ui->treeView->showNormal();
}
I would appreciate any help or advice, thanks.
-