How to Add custom shape button in fixed Location in QWidget - qt

I am new to Qt. First look at the image.
http://i225.photobucket.com/albums/dd200/saravanan_comp2001/sample.png
i already created custom shape button (inherit the QWidget). now the problem is adding the buttons into another widget(Parent QWidget).
How to add this button in Fixed location and some times i need to add the buttons in overlap.
i can't use any Layout method. Please help me to fix the problem

Just create your custom shape button with the QWidget as parent and set the position using the move function.

Related

Position JavaFX Button in a specific location

My Question is how can i position a javafx button in a specific location.
All the time that i tried to do this simple code is resulting that the Button is only located in the Center of the screen and not on my desired location.
(I'm using StackPane)
Code:
Button button = new Button();
button.setLayoutX(x);
button.setLayoutY(y);
Thanks in advance ,
Amit.
If you want to specify the exact co-ordinates of your node, you can use a Pane instead of StackPane.
Your button, if added to a StackPane or similar layout which supports alignment, must use the translate properties to move the button. You cannot use setLayoutX() or setLayoutY() with these layouts.
Try using the following command to move the button from its initial location :
button.setTranslateX(10);
button.setTranslateY(20);

An image at a specific point in Qt

I am trying to place a .png image(firm logo) at a specific point(coordinate). I've put several buttons, one after another, and now I want the image to be displayed just below these buttons. The code below should do the trick, but the coordinates are simply not working.
//QLabel myLabel; QVBoxLayout *layout; // class members, initialized with 'this'
QPixmap pixmap("v.png");
myLabel.setPixmap(pixmap);
myLabel.setMask(pixmap.mask());
myLabel.setGeometry(QRect(312, 454, 21, 20));
layout->addWidget(&myLabel);
How should I modify the code to simply include this image, possibly at a specific coordinate (just as with QPushButton)? Note that commenting out the last line removes the image, but, even when the image is shown, the buttons cannot be clicked (and they are not part of 'layout') Please provide code that would achieve image positioning with given coordinates.
QLayout is a controller which position widgets added to it. That is why it has no any sense to set coordinates to a widget and then place it to a layout. The layout will change the widget coordinates as soon as the widget is shown.
Futhermore, if you ask how to set certain position in coordinates, you shouldn't use QLayout at all, because it will change any position you set.
QPixmap pixmap("v.png");
myLabel.setPixmap(pixmap);
myLabel.setMask(pixmap.mask());
myLabel.setFixedSize(21, 20);
myLabel.move(312, 452); //ensure that this coordinates are in you widget
myLabel.show();
You will have to either show the label or put it in a layout or make sure it was given a parent in the constructor.
myLabel.setParent(parent_window)
The setParent method might also need you to show.
myLabel.show()
or
layout.addWidget(myLabel)

QTextEdit: How to add fixed position text on top of an image

I am using QTextEdit to implement an editor. One of the requirements I have is to add fixed position text on top of an image.
For example:
I have an image of dimensions: 300x300. I need to add text beginning at the location (20, 20) of the image and ensure that the text does not flow beyond the width of the image.
Something like below:
I am thinking that if I can add a QGraphicView, I can add the image and position text appropriately. Is this possible? Is there a way to introduce a graphic element into a QTextedit? If not, what is the right approach?
Is there a way to introduce a graphic element into a QTextEdit? If not, what is the right approach?
You could look at this the other way and add the QTextEdit to a QGraphicsScene. The graphics scene provides a QGraphicsProxyWidget to add standard Qt widgets.
Therefore, you could create a QGraphicsScene and QGraphicsView. Add a QGraphicsPixmapItem for the image and add the QTextEdit item with a call to QGraphicsScene::addWidget, which returns a QGraphicsProxyWidget, allowing you to position, scale and resize the widget.
Alternatively, you could start with a QGraphicsItem, inherit from that and create your own object which encapsulates the image and proxy object of the QTextEdit.
There are other ways of tackling this too, but I'd probably go for the custom QGraphicsItem. It also depends on your specification, but you can add text items in a graphics scene, without the QTextEdit, though you'd probably have to implement the editing feature, if this is required.

Flex 3 - Custom tab navigator

I'm trying to create a custom tab navigator that has to look like this http://www.freeimagehosting.net/uploads/b470d024c4.jpg.
Also, when there's a rollover, the borders of the arrow have to be in blue (like the label in the current tab).
For that purpose, I've created a custom component: a hbox containing a label and a canvas with 3 images inside (for the arrow tip that has to change depending on the currentState).
Then, I thought of overlapping the components in order to get the blue highlight color (ex: arrow button 3 is over arrow button 4. The image of the arrow tip in button 3 will be transparent outside the arrow, so that we can see the black color of the following button).
I'm now trying to position the components inside the canvas ... but I cannot.
After the creationComplete event, I assign the label text and I was calculating the coordonates of the component but it doesn't take into account the label width... -_-'
Any ideas?
Thanks. Regards,
BS_C3
Read up on the Flex Component LifeCycle. You should be positioning and sizing your child components in the updateDisplayList() method; not in a creationComplete handler.
You should assign the label text in either commitProperties or createChildren depending upon when you know what it is.
If you want to share some code, we may be able to hone in on the exact problem. If you run code like this:
myLabel.text = 'Blahblahblahblah';
trace(myLabel.width);
I would expect that the width has not changed to reflect the new text because the myLabel has not gone through it's own component lifecycle steps yet.

How to place one widget over another in Qt

i have a window in Qt, on that i am drawing a picture. now i want to place the progressbar over it.
how can i do that?..
steps i am following to do
Create a window,
Draw picture in paint event of window
Then create QGridLayout layout, add your window
Display over it.
suppose i want to add progress bar, over a portion of picture window. how can i do that
i dont think its possible to implement in window paint event.
please assist me
Thanks
You can add the progress bar as child of your QWidget without adding it in the layout. This will draw the QProgressBar into the QWidget. Since you are not using the layout you will have to manually manage the position of the QProgressBar.
I think that just adding a progress bar widget to your grid layout should work.

Resources