QPushButton has duplicated text after Qt upgrade
Asked Answered
F

2

8

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).

illustration of the problem

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...

EDIT

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:

enter image description here

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);
    }
Fireguard answered 27/4, 2015 at 11:24 Comment(6)
Can you share some of the code you're using?Hartebeest
Sure, but to be honest, I don't exactly know where to look for the bugs like this.Fireguard
Interesting. Unless you've changed any of the code auto-generated by uic, I doubt that's the issue. Does it look strange in Qt Designer? Have you gone through the Qt bug tracker for similar reports?Hartebeest
Yep, nothing strange in Creator. And yes, I have looked trough the Qt bug tracker but nothing similar.Fireguard
I don't have any other ideas. This smells like a bug to me, not something you've done wrong or incorrectly.Hartebeest
Other interesting fact: on a different device the entire UI looks different. I will look for the used style definition.Fireguard
F
1

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.

Fireguard answered 29/5, 2015 at 10:50 Comment(0)
H
2

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.

Hightension answered 18/11, 2015 at 13:46 Comment(1)
Don't know about the above discussion on your answer, but this solved it for me, thanks.Shutdown
F
1

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.

Fireguard answered 29/5, 2015 at 10:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.