How to replace previous image with new image in QGrapicsScene - c++

In Constructor, using QGraphicScene I'm adding many widgets and one image using Qpixmap. when I want to replace only image. i'm able replace the image but these widgets are not coming ..`
QPixmap *bkgnd=new QPixmap(":/res/Clamp Down - Pedistal Down - Arm Retracted - Complete.jpg");
m_bkImgScene.addPixmap(*bkgnd);
m_bkImgScene.addItem(&m_txtForelinePsr);
m_txtForelinePsr.setPos(POS_FORELINEPSR);
m_bkImgScene.addItem(&m_txtMechPump);
m_txtMechPump.setPos(POS_MECHPUMP);
m_bkImgScene.addItem(&m_txtRoughLnPsr);
m_txtRoughLnPsr.setPos(POS_ROUGHLINEPSR);
m_bkImgScene.addItem(&m_txtHeBartn);
m_bkImgScene.addItem(&m_txtHeMfc);
m_bkImgScene.addItem(&m_txtIonGfb);
m_bkImgScene.addItem(&m_txtProBaratronfb);
m_txtProBaratronfb.setPos(POS_PROBARATRONFB);
m_bkImgScene.addItem(&m_txtChamberPsr);
m_mapTxtWxs[CHAMBERPRESSUREFEEDBACK] = &m_txtChamberPsr;
m_txtChamberPsr.setPos(POS_CHAMBERPSR);`

mypixmap->load("secondimage_path");
mylabel->setPixmap(mypixmap);

Related

Tkinter Background not showing transparent

Hey im a newbie in python in my code there is a animated gif that play whenever i run the code. The gif image is actually transparent when open in adobe etc. but the problem is when i run the code.The frame which is the color gray included in the gif.I want to remove the color gray so that the only thing that can see is my only animated gif
This is my code:
# mimic an animated GIF displaying a series of GIFs
# an animated GIF was used to create the series of GIFs
# with a common GIF animator utility
import time
from Tkinter import *
root = Tk()
imagelist = ["dog001.gif","dog002.gif","dog003.gif"]
# extract width and height info
photo = PhotoImage(file=imagelist[0])
width = photo.width()
height = photo.height()
canvas = Canvas(width=width, height=height)
canvas.create_line(0,240,640,240, fill='blue')
canvas.pack()
# create a list of image objects
giflist = []
for imagefile in imagelist:
photo = PhotoImage(file=imagefile)
giflist.append(photo)
# loop through the gif image objects for a while
for k in range(0, 10):
for gif in giflist:
canvas.delete(ALL)
canvas.create_image(width/2.0, height/2.0, image=gif)
canvas.update()
time.sleep(0.1)
root.mainloop()[![enter image description here][1]][1]
dog001.gif
dog002.gif
dog003.gif
As described here, making a Tkinter window transparent is possible, but depends on your OS.
If you are on Windows, just add the following lines after creating the root:
root = Tk()
# Hide the root window drag bar and close button
root.overrideredirect(True)
# Make the root window always on top
root.wm_attributes("-topmost", True)
# Define a transparent color
root.wm_attributes("-transparentcolor", '#eeefff')
Then set your canvas' background color as the transparent color defined above:
canvas = Canvas(width=width, height=height, bg='#eeefff', highlightthickness=0)

display a lot of images with Qt

I want to display a lot of images in my Qt application, for that I have created a button that when clicked will access to the computer's user and add images. My issue is that I don't know how to display these images in the application.
Here is my Code:
void Mainwindow::on_pushButton_pressed()
{
QStringList fileName = QFileDialog::getOpenFileNames(this,tr("Open Image"),
"C:/qt-win-opensource-src-4.5.0/bin/",
tr("Image Files(*.png *.jpg *.bmp *.avi *.gif)"));
iterator = new QStringListIterator(fileName);
label = new QLabel;
if(iterator->hasNext())
{
label->clear();
label->setPixmap(QPixmap(iterator->next()));
label->show();
}
}
You should use a scroll area for all those images you want to be displayed. You can set a layout depending on how you want those images to be arranged and display them using instances of QLabel.
iterator = new QStringListIterator(fileName);
label = new QLabel;
if(iterator->hasNext())
{
label->clear();
label->setPixmap(QPixmap(iterator->next()));
ui->scrollArea->layout()->addWidget(label); // need to add a scroll area widget in your ui file
// and set layout to it (horizontal, vertical, grid etc.)
}
This way, should be no problem and your labels should be displayed properly.

Getting value from QTableWidgetItem

I want to set QTableWidgetItem's data as an image. imagePath may be different each time.
QTableWidgetItem *itemMedia = new QTableWidgetItem();
itemMedia->setTextAlignment(Qt::AlignCenter);
itemMedia->setData(Qt::DecorationRole, QPixmap(imagePath).scaled(width, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation));
m_table->setItem(0,0,itemMedia);
m_table->setItem(0,1,itemMedia);
m_table->setItem(1,0,itemMedia);
m_table->setItem(1,1,itemMedia);
I've created it nicely. Next, I want to get data with this:
connect(m_table, SIGNAL(itemClicked(QTableWidgetItem *)), this, SLOT(onItemClicked(QTableWidgetItem *)));
void MUCSharedMedia::onItemClicked(QTableWidgetItem *item)
{
qDebug()<<"DecorationRole: " <<item->data(Qt::DecorationRole).toString();
qDebug()<<"DisplayRole: " <<item->data(Qt::DisplayRole).toString();
}
Actually I want imagePath in one of this role , but I get this line in Application Console:
DecorationRole: ""
DisplayRole: ""
How to get value? Any suggestion?
EDITED:
I want to show image on each QTableWidgetItem after that I want to store image path of images which I've shown.
If you need to store QString actually, you need DisplayRole two times:
itemMedia->setData(Qt::DisplayRole, imagePath);
qDebug()<<"DisplayRole: " <<item->data(Qt::DisplayRole).toString();
EDIT: if you need to show image and get image file path I suggest you another way:
1) Set image like you did:
itemMedia->setData(Qt::DecorationRole, QPixmap(imagePath).scaled(width, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation));
2) Set image path using Qt::UserRole
itemMedia->setData(Qt::UserRole, imagePath);
When you need it:
qDebug()<<"File Path: " <<item->data(Qt::UserRole).toString();
But application will use image for displaying.
QTableWidgetItem::data() returns QVariant where you'll get the data with QVariant::value().
Alternatively, use QTableWidget::text().
http://doc.qt.io/qt-5/qtablewidgetitem.html
You store a QPixmap:
itemMedia->setData(Qt::DecorationRole, QPixmap(imagePath).scaled(width, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation));
but try to extract it as a QString:
qDebug()<<"DecorationRole: " <<item->data(Qt::DecorationRole).toString();
That will always give you a default-constructed (i.e. empty) QString.
You want to retrieve it as a QPixmap:
item->data(Qt::DecorationRole).value<QPixmap>()
(though there's little point sending that to a QDebug stream!)
There's a good chance you want the original, unscaled pixmap. In which case, you'll need to store that as well, perhaps in Qt::UserRole:
itemMedia->setData(Qt::UserRole, QPixmap(imagePath));
and change the retrieval to match.

Qt: save entire QScrollArea contents as an image

I am trying to save the contents of a QScrollArea as an image.
Currently, I am doing it this way...
QPixmap pixmap(ui->overview->rect().size());
ui->overview->render(&pixmap, QPoint(),QRegion(ui->overview->rect()));
QString saveFilename = QFileDialog::getSaveFileName(this, "Save as", "Choose a filename","PNG(*.png);; TIFF(*.tiff *.tif);; JPEG(*.jpg *.jpeg)");
if(!pixmap.save(saveFilename))
{
QMessageBox::warning(this, "Error","File could not be saved", QMessageBox::Ok);
}
But if the contents exceed one screen (and you need to scroll to see the entire image) and I save that,
the image only shows the part of the screen it's currently on.
How can I save the full contents of the scrollArea so that the image shows the entire thing, and not just a part of it?
QImage img(ui->scrollAreaWidgetContents->size(),QImage::Format::Format_ARGB32);
QPainter painter(&img);
ui->scrollAreaWidgetContents->render(&painter);
bool istrue = img.save("/file.jpg");

Issue with shadows/Opacity on sprites in cocos2d (.png format)

I'm having trouble understanding why sprites with shadows (%opacity layer) looks different in ps and on screen. Here is the comparison:
This is simply because of image formate you set. I guess you set RGBA4444 in code or while exporting spriteSheet. Also remove checkmark Premultiply alpha in texture packer.
Also check in AppDelegate Class:
CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
pixelFormat:kEAGLColorFormatRGBA8 //Guru - replaced kEAGLColorFormatRGB565 with kEAGLColorFormatRGBA8
depthFormat:0 //GL_DEPTH_COMPONENT24_OES
preserveBackbuffer:NO
sharegroup:nil
multiSampling:NO
numberOfSamples:0];
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];