Miscellaneous Notes on QT Interface Development (4)

Adjust button size according to text size   
QFontMetrics fmwelcome(m_rightButton->font());
int wid = fmwelcome.boundingRect(context2).width();
m_rightButton->setFixedWidth(wid);
qDebug()<<"context2 width --- ---------------------"<<context2<<wid;
//Redraw button background text
//Background text style
void MyButton::paintEvent(QPaintEvent *event )
{         QRect m_rect= QRect(0, 0, width(), height());         QPainter painter(this);         QPen pen;         pen.setColor("#ff0000");         painter.setPen(pen);         QFont font;         font .setPixelSize(12);         font.setBold(true);         painter.setFont(font);









        painter.drawText(m_rect, getButtonText(), QTextOption(Qt::AlignHCenter | Qt::AlignVCenter));
        QWidget::paintEvent(event);
}


pro file learning
https://www.cnblogs.com/boright88/p/6264642.html
https://www.jianshu.com/p/93153d7296a1
configuration of different platforms
https://blog.csdn.net/weixin_30553065/article /details/95269284
Multi-project compilation
https://blog.csdn.net/luoyouren/article/details/51210740

Since this method has been deprecated, explore another way to get the screen size
QDesktopWidget* desktopWidget = QApplication::desktop();
QRect applicationRect = desktopWidget->screenGeometry();
qDebug()<<"applicationRect------ -------------"<<applicationRect;

#include <QScreen>
int screen_width = QGuiApplication::primaryScreen()->availableGeometry().width();
int screen_height = QGuiApplication::primaryScreen()->availableGeometry().height();
Reference URL: https:// blog.csdn.net/qq_36393978/article/details/113074946
set window to maximize
setWindowState(Qt::WindowMaximized);
reference URL: https://www.cnblogs.com/GEEK-ZHAO/p/12370130.html
 

Guess you like

Origin blog.csdn.net/caicai_xiaobai/article/details/121852860