How to resize Window to content?
Unsolved
General and Desktop
-
In the BarView, subclass of
QGraphicsView
, I've thisslot
:void BarView::onShowPopup(BarSeries &s, QPointF p){ popup->setGeometry(p.x() + 10, p.y() + 10, 0, 0); popup->setData(s); popup->show(); }
I don't give
popup
any width and height here.Popup
has these:Popup::Popup(QWidget *parent) : QWidget(parent){ setWindowFlags(Qt::FramelessWindowHint | Qt::SubWindow); setPalette(Qt::darkGray); auto lay = new QVBoxLayout(this); setLayout(lay); table = new QTableView(this); model = new QStandardItemModel(table); model->setColumnCount(3); table->setModel(model); table->horizontalHeader()->hide(); table->verticalHeader()->hide(); table->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); lay->addWidget(table); setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); } void Popup::setData(BarSeries &s){ model->clear(); auto name = new QStandardItem(s.name); auto val1 = new QStandardItem(QString::number(s.value1)); auto val2 = new QStandardItem(QString::number(s.value2)); model->appendRow(QList<QStandardItem*>() << name << val1 << val2); table->resizeRowsToContents(); table->resizeColumnsToContents(); table->adjustSize(); adjustSize(); }
this is how it looks:
I've tried those resize/size policy/adjust BUT doesn't work! It always gets a fixed size! How to resize it to content size? One more question, I've
setPalette(Qt::darkGray)
in the Popup, from where does the table get black background? I want that to have the Popup background.