PDA

View Full Version : Replacement of Images



merry
26th February 2007, 09:37
HiHi all

I am using Qt3.1 for Linux Operating System.

My Problem is that how can I replace one image with another,

By using Connections(Signals and Slots)


connect(listView,SIGNAL(pressed(QListViewItem*)),t his,SLOT(reverse_images(QListViewItem*)));

it can replace images.

But what I want is after replacing images when I pressed again on an item it can again replace image with the first one(initial one).

Pls do reply with an eg.

Thanx and Regards
merry

wysota
26th February 2007, 10:04
But what is the problem exactly? What did you already try?

merry
28th February 2007, 10:54
Hi

Exactly My Problem is that
I am having a treeStructure of Files and Folders and I had represented files and folders with different different images.

Foreg.


Files are represented by Fileunchecked.png
Folders are represented by Folderunchecked.png

now when i pressed any File or Folder it can be replaced by another image like

Fileunchecked.png is replaced by Filechecked.png
and
Folderunchecked.png is replaced by Folderchecked.png

For this I used the concept of Connections using Signals and Slots

connect(listView,SIGNAL(pressed(QListViewItem*)),t his,SLOT(reverse_images(QListViewItem*)));

By using this the images are also changed.


But now I want when I again Click on any File or Folder (that are checked) can be replaced by File or Folder (that are unchecked)

That is

Filechecked.png is replaced by Fileunchecked.png
and
Folderchecked.png is replaced by Folderunchecked.png

wysota
28th February 2007, 11:01
I still don't see a problem... Just extend your method to flip the image back to the one that was there before. If you want to make the task easier, you can subclass the list item and introduce an additional member holding the item state (checked/unchecked).

BTW. Why not use QCheckListItem instead? You can subclass it and draw a pixmap instead of a checkbox.

merry
1st March 2007, 07:33
Hi Wysota

Actually i m new to Qt3.1 , So can you Please explain the use of Subclass with example

Thanx
Merry:)

wysota
1st March 2007, 10:16
Are you familiar with C++ and its concept of inheritance? Your problem is strictly C++.

http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html