I have dared to start learning Qt with very basic C++ knowledge. I am asked to implement a class for image in Qt.
In my application whenever I will select a picture it will have some properties, such as, when I will move the window the QLabel that is containing my image will also increase in size of width and height without loosing the aspect ratio.
I do not expect some finished code. But I want to know how to think for that. I am having problem to make an algorithm.
I am expecting some help to solve this problem. Thanks in advance!
You should begin by running some sample code and seeing how they work. There are lots of examples that display images in various ways. Step through them to see if you can understand what each step does.
Try to write a simple "Hello world!" app in Qt. Then try adding an image display to it. The solution to the task you describe should become straightforward as you develop knowledge of Qt.
Related
I'm comfortable with C++ but brand new to Qt. I apologize for my ignorance as I'm sure this is a very simple question. I'd like to make a custom clickable widget, basically a push button that is just a black square with Qt designer, but don't have any idea on where to start.
EDIT: after fumbling around I think I'm an epsilon closer.
I created a black_box.png file. In the resource browser I created a new resource and prefix, and added the black_box.png. Any advice from here?
You have a few options for what you want to achieve.
You can use custom painting to draw a new button that subclasses QPushButton, this is reasonably involved and provides a huge amount of flexibility to build it to your requirements.
You can use Qt's stylesheets mechanism to style it, you can get more information on it here: http://doc.qt.io/qt-5/stylesheet.html
Or you can set a QPixmap of your image to be a button icon, and size your button to match it, there's a good answer on how to do this on this question: How to set image on QPushButton?
I have a simple to do tree application that displays a QTreeView inside of a QMainWindow. I want to give the user the ability to change the magnification level of the content (using a spinbox most likely), but without actually changing the underlying font size of the text.
Is there a way to do this without changing my whole app to a QGraphicsScene? The app is just showing a good-old fashioned tree with text, no graphics or anything fancy other than wanting to change the magnification of the view; hence, I am thinking that switching to a graphics scene would be overkill.
Or, am I wrong, and switching to a graphics scene is the only simple way to do it?
Note a trimmed down version of the app is at Code Review. It contains a SSCCE, but is a bit long to post here.
In a site discussing how to put widgets on a scene, trolltech wrote (emphasis added):
I myself and several other Trolls’ve spent some time researching this
topic [how to embed a widget in a QGraphicsScene]. It’s not trivial;
most solutions to embedding widgets into a scene end up with several
serious drawbacks. That’s also why Qt doesn’t have any off-the-shelf
solution to this.
Widgets cannot be scaled or rotated, but graphics items can.
This suggests I cannot perform, in a simple way, the operations I want to on my QWidget by itself. That is, perhaps I need to add it to a scene, which is what I was trying to avoid. If that is the answer, then I'll accept it and start a new question if I get stuck doing that.
Note I just found this question, which is pretty much a duplicate, and does not have an (accepted) answer.
Related content
http://www.qtcentre.org/threads/62745-Zoom-a-view
QTableView Zoom In/Out
Drawing widgets (such as buttons) over QGraphicsView
QGraphicsView Zooming in and out under mouse position using mouse wheel
https://forum.qt.io/topic/15308/qgraphicsview-zooming-with-qslider
https://wiki.qt.io/Smooth_Zoom_In_QGraphicsView
As suggested by the docs quoted from trolltech in the original question, there is no built-in method to zoom on a view.
If the goal is to avoid the use of QGraphicsViews, the simplest way to separate the size of the font on the screen, versus the size of the font saved or printed, is to basically have two fonts. One to be displayed on the screen you can call 'zoom', versus the other to be saved/printed and call that 'font size'.
I got this idea from qtcentre (in a post I added to the original post too):
http://www.qtcentre.org/threads/62745-Zoom-a-view
I want to make a program using qt.
I have to make a bitmap editor for special purposes.
I had been looking widgets that could allow me to get this task done, one of them is QGraphicsView with QGraphicsScene.
As expected, I want my program to have many features.
They are listed below:
Exporting to image formats such as .bmp.
Support for clipboard, copy and paste. I hope this clipboard can be compatible with other similar programs.
The image must have a resolution. I mean the pixels of the screen can be bigger than the pixels of the image and vice-versa.
Selecting squared areas.
So, what I need to know is if I am using the correct widget. If not, which widget can I use? which are the member functions of the widget that I need to know?
There several ways to achieve what you want, but as your question is too broad, I would suggest looking at the Qt Scribble example and come back with specific questions relating to what it doesn't do.
The link suggested previously was replaced with a new one that points to the corresponding Qt 5 example.
I've been looking for some inspiration with wxpython as far as the GUI goes. Everything in the demo looks boring and uninspiring so I want to go in my own direction but I can't figure out how to use my own buttons I made in photoshop or my own background images.
I'm kind of new to GUI programming so I ask if you could please be clear in what steps I should take. Once I intialize the frame...how to I load my custom buttons, or set the panel background?
As acattle pointed out, I already wrote on how to change a panel's background. You should note that wxPython isn't a themable GUI toolkit. It uses the native widgets of the OS wherever possible and most of the time, those just aren't very themable. If you need that, then you should look at Tkinter's (especially ttk) or pyside/pyQt.
If you need bitmap buttons, there are several options:
BitmapButton
GradientButton
AquaButton
PlateButton
I did some googling and I found this tutorial for setting the background of panels.
A bit more googling and I found this post talking about wxPython's Bitmap Button Class and showing some code examples.
I would suggest being very very careful designing your GUI if you're going to use custom images. You need to pay special attention to your spacing and your text sizes or your GUI might come out looking like crap.
i am learning QT, i am not getting how to get the picture control in QT?.
in .net we have picture control right same way i need in QT.
i know text edit support pictures but is there any alternatives.
please tell if so.
Thanks
I assume that you mean a control for showing pictures. In that case, simply use a QLabel and call setPixmap. There is a more versatile, but less polished picture widget here.