How can I retrieve a file icon and draw it on a QGraphicsView?
How can I retrieve a file icon and draw it on a QGraphicsView?
Where do you want to read the file icon from ?
As for adding icon in graphics view, you can simply set icon to a QLabel and add the label to graphics scene.
Alternatively you can use QGraphicsPixmapItem![]()
I want to read it from any computer file, folder and shortcut on a computer.
Lets say: select "myapp.exe", get its icon, and display in QGraphicsView.
So... anyone?
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
After realy trying to find out how to set up a QGraphicsView, I give up. I get many errors and no image renders. Does anyone have a sample code?
This:
will result in this:Qt Code:
{ ui->setupUi(this); setCentralWidget(gv); scene->setSceneRect(0, 0, 500, 500); gv->setScene(scene); scene->addItem(ritem); // first way to add a pixmap scene->addItem(pitem); pitem->setPos(100, 100); // second way }To copy to clipboard, switch view to plain text mode
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
Thanks! That worked. But now I have another problem:
Thats code I found here in the Forum.
Then I do the following:
But nothing renders on the screen. An idea why?Qt Code:
QGraphicsPixmapItem *pitem2 = new QGraphicsPixmapItem(QPixmap(appIcon.pixmap(2,QIcon::Normal,QIcon::On))); scene->addItem(pitem2); pitem2->setPos(100, 100);To copy to clipboard, switch view to plain text mode
Thanks! That worked. But now I have another problem:
Thats code I found here in the Forum.
Then I do the following:
But nothing renders on the screen. An idea why?Qt Code:
QGraphicsPixmapItem *pitem2 = new QGraphicsPixmapItem(QPixmap(appIcon.pixmap(2,QIcon::Normal,QIcon::On))); scene->addItem(pitem2); pitem2->setPos(100, 100);To copy to clipboard, switch view to plain text mode
I think your problem might be here:
First of all QIcon::pixmap() already returns QPixmap so invoking QPixmap constructor again is not necessary (but it is not an error). The strange thing in your code is that "2"... it means that you want and pixmap of size 2x2... not so big for me. Try changing it to 32 for example and check if it helps.Qt Code:
To copy to clipboard, switch view to plain text mode
For me this works fine:
Qt Code:
tr("Choose file..."), qApp->applicationDirPath()); QFileIconProvider fip;To copy to clipboard, switch view to plain text mode
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
Thanks! Sorry for the double post. I have a new issue on icon grabbing with diferrent file types, should I open a new thread?
Bookmarks