Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to resize Window to content?
Forum Updated to NodeBB v4.3 + New Features

How to resize Window to content?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 197 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    deleted385
    wrote on 16 Nov 2021, 07:17 last edited by deleted385
    #1

    In the BarView, subclass of QGraphicsView, I've this slot:

    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:

    x1.gif

    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.

    1 Reply Last reply
    0

    1/1

    16 Nov 2021, 07:17

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved