Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 58
Registered: ‎09-25-2012
My Device: Dev Alpha, Z10
My Carrier: MTS

QPixmap and QBitmap is it possible to use in the Cascades?

[ Edited ]

Hi all,

 

I just want to do something like this

 

QImage image("icon.png");
QImage newImage(image.size(), image.format()); newImage.fill(newColor); QImage mask = image.createAlphaMask(); QPainter p(&newImage); QBitmap bmpMask = QBitmap::fromImage(mask); // crash //QPixmap bmpMask = QPixmap::fromImage(mask); // crash p.setClipRegion(QRegion(bmpMask));

 

but it always crashed!

 

Process terminated SIGSEGV code=1 fltno=11 ip=7abf62cc(/base/usr/lib/qt4/lib/libQtGui.so.4.8.5@_ZN15QGraphicsSystem23createDefaultPixmapDataEN11QPixmapData9PixelTypeE+0x17) mapaddr=001f62cc. ref=00000000

 

 

Any body know how I can solve this problem?

 

My goal it's recolor icon on the fly..

 

Thanks!

Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: QPixmap and QBitmap is it possible to use in the Cascades?

You should be able to do this, yes.

 

Take a look at the carousel sample which uses QPainter to dynamically modify images:

 

https://github.com/blackberry/Cascades-Community-Samples/tree/master/stumpers/bbjamcarousel

 

QVariant Carousel::createMirrorImage(QString inputFName)
{

  if (inputFName.isEmpty())
    return QVariant::fromValue(0);

  char buff[1024];
  QString prefix = QString(getcwd(buff, 1024));
  inputFName = prefix + "/app/native/assets/" + inputFName;

  QImage inputQImage(inputFName);
  QImage mirrored_part = inputQImage.mirrored(false, true);
  QPoint start(0, 0);
  QPoint end(0, mirrored_part.height());
  QLinearGradient gradient(start, end);

  gradient.setColorAt(0.0, Qt::gray);
  gradient.setColorAt(0.22, Qt::black);
  gradient.setColorAt(1.0, Qt::black);
  QImage mask = mirrored_part;
  QPainter painter(&mask);
  painter.fillRect(mirrored_part.rect(), gradient);
  painter.end();

  mirrored_part.setAlphaChannel(mask);
  bb::cascades::Image mirrored_image = fromQImage(inputQImage, mirrored_part);
  return QVariant::fromValue(mirrored_image);

}

 

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Contributor
Posts: 11
Registered: ‎12-13-2012
My Device: Blackberry Z10, Blackberry Playbook 16GB/64GB
My Carrier: Rogers

Re: QPixmap and QBitmap is it possible to use in the Cascades?

The carousel sample doesn't use a QPixmap or a QBitmap which are the problem classes.

 

As well as an error when trying to change a QImage to a QPixmap if you just try to create a new QPixmap you get:

'QPixmap: Cannot create a QPixmap when no GUI is being used'

Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: QPixmap and QBitmap is it possible to use in the Cascades?

You said your goal was to recolour your image. Can you not achieve this in the way carousel manipulates images?
--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Contributor
Posts: 11
Registered: ‎12-13-2012
My Device: Blackberry Z10, Blackberry Playbook 16GB/64GB
My Carrier: Rogers

Re: QPixmap and QBitmap is it possible to use in the Cascades?

I can recolour images on the fly based on the carousel sample but I'm not sure what all the OP hopes to do. There are some classes that can be used for getting effects when drawing that won't work without QPixmap.

 

After looking a little further it looks like QPixmap and QBitmap are integrated tightly with Qt's rendering engine. This, coupled with the fact that BlackBerry doesn't have documentation for them in their native development documentation, makes me believe the short answer to the question posed in the title is no.

Developer
Posts: 58
Registered: ‎09-25-2012
My Device: Dev Alpha, Z10
My Carrier: MTS

Re: QPixmap and QBitmap is it possible to use in the Cascades?

[ Edited ]

Hi guys,

thank you for replies!

 

Currently I found alternative solution for recolor images on the fly witchout QPixmap. I just use alpha chanel of image as mask:

// load source icon to QImage
QImage sourceImage("my_icon.png");
QColor color("#FF0000"); // your wanted color

// Create new image...
QImage colorImage(sourceImage.size(), sourceImage.format());
// ...fill it by wanted color
colorImage.fill(color);
// ...and then apply alpha chanel of source image
colorImage.setAlphaChanel(sourceImage.alphaChanel());

// now convert it to bb::cascades::Image
bb::cascades::Image image;
image = bb::ImageData::fromPixels(colorImage.rgbSwapped().convertToFormat(QImage::Format_ARGB32_Premultiplied).bits(), bb::PixelFormat::RGBA_Premultiplied, colorImage.width(), colorImage.height(), colorImage.bytesPerLine());

 

But I'm still don't know possible or not to use QPixmap in the Cascades Project...

Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: QPixmap and QBitmap is it possible to use in the Cascades?

The answer is a qualified "no" I'm afraid.

 

Basically to use anything from QtGui in a Cascades application can give rise to a conflict. The QtGui module your application needs an instance of QApplication, which derives from QCoreApplication. A Cascades application needs an instance of bb::cascades::Application however and this derives from bb::Application which itself derives from QCoreApplication. You can have only one application instance and the two classes I mentioned are different branches of the same inheritance tree. I'm guessing that your crash is the result of not having a QApplication, since it performs some needed initialization for QtGui.

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Developer
Posts: 1,028
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: QPixmap and QBitmap is it possible to use in the Cascades?

If it really is an initialization problem, then the OP should be able to inherit from bb::cascades::Application and write their own QtGui initialization code in the constructor. I'm not saying it would be easy, but it may be doable. Take a look at the source code for QApplication and see what it is doing.

 

I already use an extended version of bb::cascades::Application so I can catch exceptions thrown from the event loop.

 


mwoolley wrote:

The answer is a qualified "no" I'm afraid.

 

Basically to use anything from QtGui in a Cascades application can give rise to a conflict. The QtGui module your application needs an instance of QApplication, which derives from QCoreApplication. A Cascades application needs an instance of bb::cascades::Application however and this derives from bb::Application which itself derives from QCoreApplication. You can have only one application instance and the two classes I mentioned are different branches of the same inheritance tree. I'm guessing that your crash is the result of not having a QApplication, since it performs some needed initialization for QtGui.






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: QPixmap and QBitmap is it possible to use in the Cascades?

[ Edited ]

I thought I read somewhere in the docs that it's advised against extending Application.

I may be wrong on this but I'm now going to spend 20 minutes looking for it. :smileyhappy:

 

Hmm, perhaps I was wrong as I can't find anything and the wording on the Application page just states,

 

'Cascades applications are not expected to subclass this class but instead instantiate it'

 

which could mean anything or nothing.

 

Of course usual C++ warning exists of being careful of extending any class not fully documented or whose source code you can't access.


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 1,028
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: QPixmap and QBitmap is it possible to use in the Cascades?

[ Edited ]

I think the passage you are referring to says that BlackBerry doesn't INTEND for devs to extend Application, but it doesn't explicitly tell you not to, and in fact doing so is the ONLY way to catch exceptions thrown from the event loop. They do make it clear, however, that Cascades apps must use Application and not QApplication.

 

I believe when they say that they don't expect devs to extend Application they are just differentiating from pure Qt development, where the normal practice is to start by inheriting from QApplication. 


BBSJdev wrote:

I thought I read somewhere in the docs that it's advised against extending Application.

I may be wrong on this but I'm now going to spend 20 minutes looking for it. :smileyhappy:

 






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.