PDA

View Full Version : Qlistwidget plugin problem



vv
8th June 2007, 14:32
Hello,
I am trying to make a qlistwidgetplugin.
I also write the my own listwidgetitem.
I want my listwidgetitems with an icon in default.
So I am setting an icon in the constructor of the listwidgetitem.

But when I add my plugin listwidget to the designer , at first time everything is
ok .. I can see the icon on the items. But when I compile and run the application
the items on the widget are seen without icon.

Have you got any idea?

Thanks in advance..

Jeroen van der Waal
8th June 2007, 19:57
Can you drop the source code?

jpn
9th June 2007, 15:15
Perhaps the icon file cannot be found? Try embedding it as resource (http://doc.trolltech.com/4.3/resources.html).

vv
11th June 2007, 09:00
My Code is here,
Now when I compile this plugin code, At first when I adding an item to the listwidget,
it is ok but when I run the application,
in the first row I see the icon, and on the other rows I see only the text that I entered
from the menu..

this is list.cpp--------------------

List::List( QWidget *parent ) : QListWidget(parent)
{

row = 0;

mMenu = new QMenu(this);
mMenuActionGroup = new QActionGroup( this );

mMenu->setFont(I90Font(FT_LUCIDA));


connect( this, SIGNAL(currentTextChanged(QString)), SLOT(currentTextChangeOccur(QString)) );
// connect (mMenu, SIGNAL(triggered(QAction *)),SLOT(menuItemSelected(QAction *)));
}

List::~List()
{

}

void List::currentTextChangeOccur(const QString &text)
{

itemText = text;
emit currentTextChanged(itemText);
}


void List :: setMenuItems( const QString &pItems )
{

//this->clear();

itemText = pItems;
QStringList list = itemText.split( QString("&&") );
QStringListIterator i(list);

while (i.hasNext())
{

printf("Setting text items\n");
QListWidgetItem *newItem = new QListWidgetItem();
newItem->setText(i.next());
QPixmap px( 32, 32 );
px.fill(I90Color(CT_GRAY));
QIcon mItemIcon;
mItemIcon.addPixmap(px,QIcon::Mode::Selected,QIcon ::State::Off);
newItem->setIcon(mItemIcon);
insertItem(row, newItem);
row++;
}

}

QString List::getMenuItems() const
{
return mMenuItems;
}

void List ::setCaption (QListWidgetItem pItem)
{
setCurrentItem( &pItem );
}

QListWidgetItem* List ::caption() const
{
return currentItem();
}
----------------------------------------------------------------------
this is listmenudialog.cpp

#include "listmenudialog.h"
#include <QDesignerFormWindowInterface>
#include <QDesignerFormWindowCursorInterface>

ListMenuDialog::ListMenuDialog(List * pBtn, QWidget *pParent)
: QDialog(pParent)
{
mBtn = pBtn;
ui.setupUi(this);
connect(ui.okButton, SIGNAL(clicked()), this, SLOT(saveList()));
//ui.menulistTextEdit->setPlainText( mBtn->getMenuItems().join(tr("\n")) );
QStringList list = pBtn->getMenuItems().split( tr("&&") );
ui.menulistTextEdit->setPlainText( list.join(tr("\n")) );
}

ListMenuDialog::~ListMenuDialog()
{

}

void ListMenuDialog::saveList()
{
if (QDesignerFormWindowInterface *formWindow
= QDesignerFormWindowInterface::findFormWindow(mBtn) )
{
QStringList list = ui.menulistTextEdit->toPlainText().split( QChar('\n') );
formWindow->cursor()->setProperty( "MENU_ITEMS", list.join(QObject::tr("&&")) );
}
accept();
}

vv
11th June 2007, 10:33
Hi,

I am getting crazy about qlistwidget plugin.

I am adding only two items but it adds three items.

At first time on the designer everything is ok but when I save form and run the application

there are three columns on the list widget.
what can be the problem..

vv
11th June 2007, 10:46
yes I am embedding as resource