简体   繁体   中英

Adding QWidget into QGridLayout adds border to layout?

Currently I have my program organized this way in QTDesigner (which I use with VS 2022): QMainWindow->centralWidget(QWidget)->QTabWidget->Tab(QWidget)->QGridLayout. All these elements are created in QtDesigner. In my cpp code I'm downloading some data and generating QTableWidget* m_table. Unfortunately after adding it to QGridLayout element, I get a black border exactly around this layout. How it's possible if it border can't be set at all for this element, at least in QtDesigner?

QTableWidget* m_table;
///(...)
ui.gridLayout->addWidget(m_table);

Look into Qt's stylesheets. You should be able to style your QTableWidget in any way you want to.

Keep in mind a QTableWidget is specialized version of QTableView , so you have set your stylesheet to a QTableView :

m_table->setStyleSheet("QTableView {background: transparent; border: 1px solid green;}");

Here are some links to get you started with Qt stylesheets:

https://doc.qt.io/qt-5/stylesheet.html

https://doc.qt.io/qt-5/stylesheet-syntax.html

https://doc.qt.io/qt-5/stylesheet-examples.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM