Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QToolButton english encode error
Forum Updated to NodeBB v4.3 + New Features

QToolButton english encode error

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chideat
    wrote on last edited by
    #1

    I have a problem of english encode error.
    My pice of code as below:
    @
    class Button:public QToolButton {
    Q_OBJECT
    public:
    Button(const QSize &size, const QString &text, QWidget *parent=NULL):QToolButton(parent) {
    setFixedSize(size);
    setCheckable(true);
    setAttribute(Qt::WA_TranslucentBackground);

        l = new QHBoxLayout(this);
        label = new QLabel(QString("<br><br><br><center>%0</center>").arg(text), this);
        qDebug()<<label->text ();
        label->setObjectName("button");
        label->setFixedSize(this->width(), this->height ());
        l->addWidget (label, 0, Qt::AlignBottom | Qt::AlignCenter);
        this->setLayout (l);
    }
    ~Button() {
        delete label;
        delete l;
    }
    

    private:
    QLabel *label;
    QHBoxLayout *l;
    };
    @
    When i create an instance as:
    @
    new Button(QSize(134, 134), "用iPhone<br>发送铃声至电脑", this);
    @

    The "iPhone" char will be displayed as "jQipof", other chars (chinese) are all right.
    I have a test on QWidget, this string displays ok.
    Is there a limitation of setting a label on QToolButton/QPushButton? or it's just a bug of them?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      QAbstractButton already handles text so one of the question is why are you currently inheriting a button like that ?

      Why not use setText with your text content ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • C Offline
        C Offline
        chideat
        wrote on last edited by
        #3

        I want to specify the point of the text on the button. By default the text is located at the center of the QToolButton. Then is there a way to specify the alignment of the text of the button?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          AFAIK, you can only decide whether the text is under or beside the icon. But not it's alignment

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • C Offline
            C Offline
            chideat
            wrote on last edited by
            #5

            It's just what i found. And finally solved this bug by change Chinese and English combination.
            Because QToolButton have some states(hover, pressed ...), I used qss to change the backgroud, and some text is need to put on the button which is not beside or under the icon, just located at the bottom of the button. so i inherited the QToolButton.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on last edited by
              #6

              Glad you were able to get it solved! If you don't mind, please edit your first post to add [Solved] to the beginning of the title. Thanks!

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved