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 set QGridLayout column width for QLabel Widgets?
Forum Updated to NodeBB v4.3 + New Features

How to set QGridLayout column width for QLabel Widgets?

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 6.8k 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.
  • C Offline
    C Offline
    CrimsonGT
    wrote on last edited by
    #1

    I have been battling with learning how to properly implement the QGridLayout into my project for a week or so now, and feel I am almost there. However, currently my setup looks like "Main Window Grid Layout -> QScrollArea -> QWidget (Container) -> QGridLayout -> populated by QLabels". When I manually set the width of all of my labels to anything larger than their default size, they don't expand the columns and just start overlapping each other. I want to show 3 columns and 5 rows, but this still seems to be just squeezing them all in.

    @void MainWindow::setupEPGTable()
    {
    QScrollArea *scrollArea = new QScrollArea();
    QWidget *contentsWidget = new QWidget(scrollArea);
    gridEPG = new QGridLayout(contentsWidget);

    //scrollArea->setWidgetResizable(false);
    scrollArea->setWidget(contentsWidget);
    contentsWidget->setLayout(gridEPG);
    contentsWidget->setMinimumSize(scrollArea->width(), scrollArea->height());
    gridEPG->setHorizontalSpacing(5);
    ui->gridLayout->addWidget(scrollArea, 1, 0, 2, 3);
    
    // Top Left Box for displaying Date/Time
    QLabel *labelDate = new QLabel("WED");
    labelDate->setFixedWidth(200);
    labelDate->setStyleSheet("background-color: #ffffff");
    labelDate->setAlignment(Qt::AlignCenter);
    gridEPG->addWidget(labelDate, 0, 0);
    
    // Left Side Menu (column 0) for displaying channel Names/Logos
    for (int i=0; i < 5; i++)
    {
        QLabel *labelChannel = new QLabel("001");
        labelChannel->setFixedWidth(200);
        labelChannel->setStyleSheet("background-color: green;");
        labelChannel->setAlignment(Qt::AlignCenter);
        gridEPG->addWidget(labelChannel, i + 1, 0);
    }
    
    QTime time = QTime::currentTime();
    getClosestHalfHour(time);
    
    // Top row (row 0) for displaying the Time Block
    for (int i = 0; i < 3; i++)
    {
        int row = 0;
        int col = i+1;
    
        // Sets the Time Label
        QLabel *labelTime = new QLabel(time.toString("hh:mm"));
        labelTime->setFixedWidth(200);
        labelTime->setStyleSheet("background-color: red; border: 1px solid yellow;");
        labelTime->setAlignment(Qt::AlignCenter);
    
        // Adjusts the time by 30 minutes for the next iteration
        if (time.minute() == 00)
        {
            time.setHMS(time.hour(), 30, time.second());
        }
        else
        {
            time.setHMS(time.hour() + 1, 00, time.second());
        }
    
        gridEPG->addWidget(labelTime, row, col);
    }
    
    // The episode contents to be displayed according to the relevant channel (row) and time slot (column)
    for (int x = 0; x < 5; x++)
    {
        for (int i = 0; i < 3; i++)
        {
            int row = x+1;
            int col = i+1;
    
            QLabel *labelEPG = new QLabel("TEST EPG");
            labelEPG->setFixedWidth(200);
            labelEPG->setStyleSheet("background-color: blue; border: 1px solid orange;");
            labelEPG->setAlignment(Qt::AlignCenter);
            gridEPG->addWidget(labelEPG, row, col);
        }
    }
    

    }@

    !http://i47.tinypic.com/34dk1nt.png(Layout Screenshot)!

    1 Reply Last reply
    0

    • Login

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