I have an Android application written in C++ using Qt Creator.
After the Qt version upgrade (from 4.8 to 5.4) I observed a strange behaviour: all QPushButton got duplicated text label, one is at the correct position and the other is shifted a bit away. This behaviour can be observed on Acer Iconia Tab A700 but not on other device (Samsung Galaxy Tab).
I have created a whole new QDialog menu in QT Creator, using just the graphical editor, but it displayed the same thing.
Did someone else observe the same thing? I am quite new in Qt, and have no idea how to fix this...
Here are some snippets:
mydialog.ui
<widget class="QPushButton" name="startButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Start</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
ui_mydialog.h
public:
QPushButton *startButton;
QPushButton *stopButton;
...
void setupUi(QDialog *MyDialog)
{
... // some layout stuff here
startButton = new QPushButton(MyDialog);
startButton->setObjectName(QStringLiteral("startButton"));
QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(startButton->sizePolicy().hasHeightForWidth());
startButton->setSizePolicy(sizePolicy);
startButton->setDefault(true);
... // later
QWidget::setTabOrder(startButton, stopButton);
}
void retranslateUi(QDialog *MyDialog)
{
MyDialog->setWindowTitle(QApplication::translate("MyDialog", "Dialog", 0));
startButton->setText(QApplication::translate("MyDialog", "Start", 0));
stopButton->setText(QApplication::translate("MyDialog", "Stop", 0));
...
}
But again, I used the Qt Creator GUI to create the dialog, so my guess is that this should be some configuration error. Or maybe something related to the retranslateUi()
function?
This is how it looks in Qt Creator:
EDIT #2
I dug up some instruction where the concrete style of the buttons were defined. Here it is:
foreach (QToolButton* bt, listOfToolButtons) {
bt->setAttribute(Qt::WA_AcceptTouchEvents);
bt->installEventFilter(scrollAreaForToolBar);
bt->setIconSize(QSize(iconSize, iconSize));
bt->setStyleSheet("QToolButton{ background-color: #051a49; border: none;}");
scrollAreaContainer->layout()->addWidget(bt);
}
I have the same problem, I solved it by setting the stylesheet. It seems to be a problem with the border, the stylesheet that solve the problem is:
border-style: outset;
border-width: 2px;
border-radius: 4px;
border-color: black;
padding: 6px;
i tried different configuration but I cannot understand which is the real one that solve the problem.
I managed some progress!
I had to recreate the entire widget and this time I gave a bit more size to it.
Just using QtCreator, scaling the main frame of the widget. Now, all button label is dispalyed correctly. Also, the size policy of the ui elements has been changed to Expanding
.
Okay, I know that this is just a treatment and not a solution which explains why it occurs, but I am happy with this result now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With