Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 648929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:53:12+00:00 2026-05-13T21:53:12+00:00

The QTableWdiget is fabulous for simple grid displays. Changing colors, fonts, etc is straightforward.

  • 0

The QTableWdiget is fabulous for simple grid displays. Changing colors, fonts, etc is straightforward.

However, I did not manage to give the grid a ‘tighter’ look with less vertical whitespace. I see that the Qt documentation talks (eg here) about

  • margin
  • border
  • padding

around widgets, but when I set these I only get changes around the entire grid widget rather than inside.

How can I set this (with a style sheet, or hard-coded options) directly to make the QTableWidget display tighter?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:53:13+00:00Added an answer on May 13, 2026 at 9:53 pm

    The code getting ‘h’ might be unsound. It was just an example. Copy & paste the following rather rudimentary code. Change the value in “setDefaultSectionSize()”, recompile, and run. You should see the difference. Setting this to 10 or 50 yields visible results. In the code above, it is possible QFontMetrics or QFont is messing something up.

    You can use whatever you want to get the height, but font size makes the most sense.

    #include <QtGui>
    
    int main( int argc, char* argv[] )
    {
     QApplication app( argc, argv );
    
     QDialog* my_dialog  = new QDialog();
     QHBoxLayout* layout  = new QHBoxLayout();
     QTableWidget* my_table_widget = new QTableWidget( my_dialog );
    
     my_table_widget->setRowCount( 10 );
     my_table_widget->setColumnCount( 10 );
     my_table_widget->verticalHeader()->setDefaultSectionSize( 15 );
     layout->addWidget( my_table_widget );
     my_dialog->setLayout( layout );
     my_dialog->resize( 500, 200 );
     my_dialog->show();
    
     return app.exec();
    }
    

    EDIT: I don’t know how to format a block of code here… forgive me. 🙂

    Edit 2: I fixed that, and the following simple tighterTable.pro file
    helps along.

    TEMPLATE = app
    TARGET =
    DEPENDPATH += .
    INCLUDEPATH += .
    
    SOURCES += tighterTable.cpp    # if that is the filename
    

    Thanks a big fat bunch for this. BTW: Editing as code is just indenting by four spaces, and/or hitting the button with the little ‘101010’ in the formatting row.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have one column in QTableWidget NOT editable. In forums I
I have what is hopefully a simple problem using a QTableWidget in Qt Designer
Is there some simple way in PyQt to store data from QTableWidget to some
I'm writing a program using Qt 4.8 that displays a table (QTableWidget) filled with
The columns of my QTableWidget do not fill in the space of the table,
QTableWidget::setItemPrototype says following. The table widget will use the item prototype clone function when
The PyQt4 QTableWidget has both cellPressed and cellClicked signals. From the name, and the
I'm trying to make my QTableWidget call some function when I change the values
I have a subclass of QTableWidget with the following code: connect(this, SIGNAL(cellChanged(int, int)), this,
Let's consider we have QWidget that contains QTableWidget (only). So we want to resize

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.