How to align vertically text inside QPushButton? - css

I'd like to know how to align vertically text inside a QPushButton. When I do ui->button->setText("help"), the text is written in the top button. I tried with CSS but nothing. Just if I write the text into the designer, it is in the centre button. However I need to do it dynamically, but I don't know which set stylesheets CSS property to put.The problem is when I convert from char * to QString.
char *key=getTraslateWord("dsfs");
ui->button->setText(QString(key));

Related

Qlabel with image as the background overlaps other Qlabels

I have a Qlabel with image as rich text and some other Qlabels on top of that as in the picture:
although I sent the Qlabel with image to back but when I run they appear as follows:
is there anyway to fix this?
Make the text labels children of the label containing the fade. Also I can not see any layouts. Did you use layouts? You could also put the fade on the widget by implementing its paintEvent(). All other widgets will be displayed on top of that.
Try right clicking the image label and clicking the send-to-back option. That might work. That should send the QLabel behind the other elements even though they appear as though they are already in front.

How to vertically align Qlistwidgetitem text with the icon?

I'm adding icons and text as Qlistwidgetitem in Qlistwidget.
icon size is 24*24, and it is on the left of the text. After adding the icon, text appears to be on the top of the available space, I want to align it vertically in the available space.
I tried itemToAdd->setTextAlignment( Qt::AlignVCenter) but it is not showing any effect.
Could you suggest any other method to do it?
See text are at the top of available space.
myQlistWidget->addItem(new QListWidgetItem( *GuiIconManager::ref().find("icon") , nodeValue()) );
*GuiIconManager::ref().find("icon") returns QIcon size of 24*24 and nodeValue() returns QString.
OS is linux.
Make sure the string you're passing into QListWidgetItem doesn't have a newline at the end of it

text display starting from bottom up qt

How would I display text in something like QTextEdit starting from bottom up? QTextEdit starts writing at the top filling down to bottom. I want to start from the bottom and then pushing the previous text up as more text is added. I figure I could hack it and simply fill the field with nextlines to reach the bottom then reprinting whatever was written before again when text is to be added, but I wouldn't want to do that unless there isn't any other way.
insertPlainText inserts text at the current text position. You could move the cursor to the start of the docuement using the moveCursor function.
Every time you want to add some text do the following:
textEdit->moveCursor(QTextCursor::Start);
textEdit->insertPlainText(textToBeAdded);

While we are using Qlabel as hyperlink text how we can remove the line below the hyperlink text in normal state?

I want the line to appear only when we hovered or press the hyperlink text not in normal state and i want to change the color of the text also. i have tried Qpalette but i found no change in color.
You can add a style attribute to your anchor tag:
QLabel *label = new QLabel("<a style='text-decoration:none' "
"href='http://www'>your link</a>);
See the HTML subset supported by Qt's rich-text widgets for details.

Change checkbox position for a QCheckBox

I have a QCheckbox in a grid layout defined as such:
self.isSubfactorCheckbox = QtGui.QCheckBox('Is &subfactor', self)
By default the checkbox is to the left of the "Is subfactor" text. I wish to move it to the right of the text.
I've tried playing around with subcontrol-position but to no avail.
self.isSubfactorCheckbox.setStyleSheet('QCheckBox::indicator{subcontrol-origin: content; subcontrol-position: top right;}')
This moves the checkbox to the right (it's still on the left of the text) but it pushes the text to the right and out of the window's edge.
This didn't help to move the text to the right:
self.isSubfactorCheckbox.setStyleSheet('QCheckBox::text{subcontrol-origin: content; subcontrol-position: top left; }')
A solution would be creating a QLabel and adding the checkbox on its right but I don't haven't found a way to underline letters in a QLabel so that the user will know which is the shortcut key. I've tried prefixing letters with & or wrapping them in <u> </u> tags.
I'd still prefer to use only a QLabel, but how would I switch the checkbox to the right of the text without the text getting pushed out.
Even easier...
Use the QWidget.setLayoutDirection method and set it RightToLeft vs. LeftToRight
You can do this in Designer or through code, it is a property or all widgets.
Use the buddy mechanism. Set the QCheckBox to the buddy of the QLabel. After that prefix & will underline the shortcut character in the label. See the documentation of the QLabel's setBuddy.

Resources