开发者

Programatically make a QToolButton identical to one from Qt Designer

I need to make a QToolButton that looks exactly like th开发者_运维问答e default QToolButton you get when you drag one into your form in Qt Designer. Simply creating a QToolButton like this:

QToolButton *toolButton = new QToolButton(this)

does not work. You get a button, but it has no background (although it does display text). I tried creating a QToolButton in a Ui file to copy from, but you can't copy one, it's just not possible.

Any ideas on how to perform something this simple?!


It works for me, but you do have to set the geometry/text on it.

you can look in the file generated by UIC on your ui file with an example QToolButton to see what you are missing.

Make sure that the toolbutton has the correct parent - this could result in drawing strangeness if it is wrong.

e.g:

QToolButton* tb = new QToolButton(ui.centralWidget);
tb->setGeometry(QRect(10, 40, 25, 19));
tb->setText("...");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜