in the ui you can see the style sheet its working perfect for making the icon show and having the text but i need to move ONLY the text so it don't lay ontop of the image border please help me out i cant seem to get the text to move over to the right about 6px
UI
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MyDelegate</class>
<widget class="QWidget" name="MyDelegate">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>352</width>
<height>301</height>
</rect>
</property>
<property name="windowTitle">
<string>MyDelegate</string>
</property>
<widget class="QListView" name="listView">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>351</width>
<height>301</height>
</rect>
</property>
<property name="styleSheet">
show-decoration-selected: 1; /* make the selection span the entire width of the view */
border:transparent;
color: black;
font: 12pt Trebuchet MS;
}
margin-left: 24px;
}
image: url(:/images/directory.png);
}
background: #EEEEEE;
}
image: url(:/images/directory-hit.png);
}
image: url(:/images/directory-hit.png);
}
image: url(:/images/directory-hit.png);
}
image: url(:/images/directory-hit.png);
}</string>
</property>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MyDelegate</class>
<widget class="QWidget" name="MyDelegate">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>352</width>
<height>301</height>
</rect>
</property>
<property name="windowTitle">
<string>MyDelegate</string>
</property>
<widget class="QListView" name="listView">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>351</width>
<height>301</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true"> QListView {
show-decoration-selected: 1; /* make the selection span the entire width of the view */
border:transparent;
color: black;
font: 12pt Trebuchet MS;
}
QListView::text {
margin-left: 24px;
}
QListView::item {
image: url(:/images/directory.png);
}
QListView::item:alternate {
background: #EEEEEE;
}
QListView::item:selected {
image: url(:/images/directory-hit.png);
}
QListView::item:selected:!active {
image: url(:/images/directory-hit.png);
}
QListView::item:selected:active {
image: url(:/images/directory-hit.png);
}
QListView::item:hover {
image: url(:/images/directory-hit.png);
}</string>
</property>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
To copy to clipboard, switch view to plain text mode
CPP
#include "mydelegate.h"
#include "ui_mydelegate.h"
#include <QListView>
MyDelegate
::MyDelegate(QWidget *parent
) : ui(new Ui::MyDelegate)
{
ui->setupUi(this);
setAttribute(Qt::WA_Hover, true);
//ui->listView->setStyleSheet("border:transparent; background:transparent; color: rgb(160, 160, 160); font: 12pt Trebuchet MS");
ui
->listView
->setViewMode
(QListView::ListMode);
ui->listView->setWrapping(FALSE);
for( int r=0; r<5; r++ )
for( int c=0; c<2; c++)
{
//QStandardItem *item = new QStandardItem( QString("L: %0").arg(r) );
//item->setIcon( QIcon ( ":/images/directory.png" ));
item->setEditable(false);
item->setCheckable(false);
item
->setSizeHint
(QSize(345,
42));
model->setItem(r, item);
}
//Setting the icon size
ui
->listView
->setIconSize
(QSize(345,
42));
//Setting the model
ui->listView->setModel( model );
}
MyDelegate::~MyDelegate()
{
delete ui;
}
#include "mydelegate.h"
#include "ui_mydelegate.h"
#include <QListView>
MyDelegate::MyDelegate(QWidget *parent) :
QWidget(parent),
ui(new Ui::MyDelegate)
{
ui->setupUi(this);
setAttribute(Qt::WA_Hover, true);
model = new QStandardItemModel(5, 2, this);
//ui->listView->setStyleSheet("border:transparent; background:transparent; color: rgb(160, 160, 160); font: 12pt Trebuchet MS");
ui->listView->setViewMode(QListView::ListMode);
ui->listView->setWrapping(FALSE);
for( int r=0; r<5; r++ )
for( int c=0; c<2; c++)
{
//QStandardItem *item = new QStandardItem( QString("L: %0").arg(r) );
QStandardItem* item = new QStandardItem(QString("L: %0").arg(r));
//item->setIcon( QIcon ( ":/images/directory.png" ));
item->setEditable(false);
item->setCheckable(false);
item->setSizeHint(QSize(345,42));
model->setItem(r, item);
}
//Setting the icon size
ui->listView->setIconSize(QSize(345,42));
//Setting the model
ui->listView->setModel( model );
}
MyDelegate::~MyDelegate()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
Bookmarks