【问题标题】:How to set text below the QToolButton in QT not below the icon如何在QT中的QToolButton下方而不是图标下方设置文本
【发布时间】:2015-07-31 06:06:55
【问题描述】:

我正在使用 QToolButton 并设置了图标。 现在我想要文本"below the QToolButton""Not below the icon"。 有什么办法可以在 C++ 中实现,Linux 中的 QT 吗?

【问题讨论】:

    标签: c++ qt text icons qtoolbutton


    【解决方案1】:

    不久前,当我为嵌入式 Linux 系统制作应用程序时,我发现自己处于相同的位置。

    我还没有找到一个直接的解决方案(我正在寻找一种使用 CSS 实现它的方法)。

    我最终做的是创建一个新的 QWidget(使用设计器)。然后将按钮放入其中,并在其下放置一个 QLabel。

    然后添加了一个简单的静态函数

    static void wdgCustomButton::create(const QString iconPath, const QString text)
    {
        // create a new button here, create some modification functions for
        // text, image and optionally QStyleSheets.
    
        // Call those here (pass the arguments)
    
        // Then return the button
        // pseudo code, (not tested):
    
        wdgCustomButton button = new wdgCustomButton( /* could pass a parent */ );
        button->setIcon( iconPath ); // function simply calls the ui->button->setIcon
        button->setText( text );     // function simply calls the ui->label->setText 
        return button;
    }
    

    然后使用代码将这些新的 QWidgets 添加到您的面板中(也许有人知道如何在默认工具栏中获取它,但我自己还没有搜索过,因为我从来不需要它)。

    this->menuButtons[menuBtnsCount] = wdgCustomButton::create( ":/Images/Warning.png", "Delete everything" );            
    this->menuButtons[menuBtnsCount]->setGeometry( QRect( /* size and position here */ ) );
    this->menuButtons[menuBtnsCount]->show();
    

    我希望这能给你一个想法来以一种简单的方式解决它!

    编辑: 抱歉,我忘记添加有关点击事件的内容。点击事件主要是为什么我用它制作了一个 QWidget! 我只是使用了连接功能[我相信整个按钮,例如:connect(this->menuButtons[0], ...]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-27
      • 2021-09-15
      • 2011-05-31
      • 2017-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多