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. I put a button in the list widget, but the position of the button is strange.

I put a button in the list widget, but the position of the button is strange.

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 353 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.
  • I Offline
    I Offline
    IknowQT
    wrote on last edited by
    #1

    401d3e29-8111-40bf-8939-94f407f34f00-image.png

    I put a button in the list widget, but the position of the button is strange.

    void wCellTypeInfo::InitListItems()
    {
    	for (int i = (int)CATEGORY::Single; i < (int)CATEGORY::Max; i++)
    	{
    		QListWidgetItem*	item = new QListWidgetItem(this->ui.listWidget);
    		QPushButton*		pBtn = new QPushButton();
    		{
    			pBtn->setFocusPolicy(Qt::NoFocus);
    			pBtn->setMinimumSize(40,80);
    			pBtn->setText(QString("%1").arg(i));
    			pBtn->setStyleSheet("Text-align: center");
    		}
    
    		this->ui.listWidget->setItemWidget(item, pBtn);
    		this->ui.listWidget->addItem(item);
    	}
    }
    
    jsulmJ 1 Reply Last reply
    0
    • I IknowQT

      401d3e29-8111-40bf-8939-94f407f34f00-image.png

      I put a button in the list widget, but the position of the button is strange.

      void wCellTypeInfo::InitListItems()
      {
      	for (int i = (int)CATEGORY::Single; i < (int)CATEGORY::Max; i++)
      	{
      		QListWidgetItem*	item = new QListWidgetItem(this->ui.listWidget);
      		QPushButton*		pBtn = new QPushButton();
      		{
      			pBtn->setFocusPolicy(Qt::NoFocus);
      			pBtn->setMinimumSize(40,80);
      			pBtn->setText(QString("%1").arg(i));
      			pBtn->setStyleSheet("Text-align: center");
      		}
      
      		this->ui.listWidget->setItemWidget(item, pBtn);
      		this->ui.listWidget->addItem(item);
      	}
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @IknowQT said in I put a button in the list widget, but the position of the button is strange.:

      but the position of the button is strange

      What does "strange" mean exactly?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Why are you using a QListWidget if you want to show a column of QPushButton ? A QVBoxLayout is better suited for that.

        Beside that, setItemWidget is not meant for what you are trying to do.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

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